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 OUT LPMIXER_INFO MixerInfo
,
672 IN PKSPIN_PHYSICALCONNECTION OutConnection
)
674 PULONG PinsRef
= NULL
, PinConnectionIndex
= NULL
, PinsSrcRef
;
675 ULONG PinsRefCount
, Index
, PinConnectionIndexCount
;
677 HANDLE hDevice
= NULL
;
678 PKSMULTIPLE_ITEM NodeTypes
= NULL
;
679 PKSMULTIPLE_ITEM NodeConnections
= NULL
;
680 PULONG MixerControls
;
681 ULONG MixerControlsCount
;
684 // open the connected filter
685 Status
= MixerContext
->Open(OutConnection
->SymbolicLinkName
, &hDevice
);
686 if (Status
!= MM_STATUS_SUCCESS
)
688 DPRINT("OpenDevice failed with %x\n", Status
);
692 // get connected filter pin count
693 PinsRefCount
= MMixerGetFilterPinCount(MixerContext
, hDevice
);
694 ASSERT(PinsRefCount
);
696 PinsRef
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * PinsRefCount
);
700 MixerContext
->Close(hDevice
);
701 return MM_STATUS_UNSUCCESSFUL
;
704 // get topology node types
705 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hDevice
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
706 if (Status
!= MM_STATUS_SUCCESS
)
708 MixerContext
->Close(hDevice
);
709 MixerContext
->Free(PinsRef
);
713 // get topology connections
714 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hDevice
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
715 if (Status
!= MM_STATUS_SUCCESS
)
717 MixerContext
->Close(hDevice
);
718 MixerContext
->Free(PinsRef
);
719 MixerContext
->Free(NodeTypes
);
722 // gets connection index of the bridge pin which connects to a node
723 DPRINT("Pin %lu\n", OutConnection
->Pin
);
725 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, OutConnection
->Pin
, FALSE
, !bInput
, &PinConnectionIndexCount
, &PinConnectionIndex
);
726 if (Status
!= MM_STATUS_SUCCESS
)
728 MixerContext
->Close(hDevice
);
729 MixerContext
->Free(PinsRef
);
730 MixerContext
->Free(NodeTypes
);
731 MixerContext
->Free(NodeConnections
);
735 /* there should be no split in the bride pin */
736 ASSERT(PinConnectionIndexCount
== 1);
738 /* find all target pins of this connection */
739 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, FALSE
, PinConnectionIndex
[0], PinsRef
);
740 if (Status
!= MM_STATUS_SUCCESS
)
742 MixerContext
->Close(hDevice
);
743 MixerContext
->Free(PinsRef
);
744 MixerContext
->Free(NodeTypes
);
745 MixerContext
->Free(NodeConnections
);
746 MixerContext
->Free(PinConnectionIndex
);
750 for(Index
= 0; Index
< PinsRefCount
; Index
++)
752 DPRINT("PinsRefCount %lu Index %lu Value %lu\n", PinsRefCount
, Index
, PinsRef
[Index
]);
755 // found a target pin, now get all references
756 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, Index
, FALSE
, FALSE
, &MixerControlsCount
, &MixerControls
);
757 if (Status
!= MM_STATUS_SUCCESS
)
759 DPRINT("MMixerGetNodeIndexes failed with %u\n", Status
);
764 ASSERT(MixerControlsCount
== 1);
766 PinsSrcRef
= (PULONG
)MixerContext
->Alloc(PinsRefCount
* sizeof(ULONG
));
770 MixerContext
->Close(hDevice
);
771 MixerContext
->Free(PinsRef
);
772 MixerContext
->Free(NodeTypes
);
773 MixerContext
->Free(NodeConnections
);
774 MixerContext
->Free(PinConnectionIndex
);
775 MixerContext
->Free(MixerControls
);
776 return MM_STATUS_NO_MEMORY
;
779 // now get all connected source pins
780 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, TRUE
, MixerControls
[0], PinsSrcRef
);
781 if (Status
!= MM_STATUS_SUCCESS
)
784 MixerContext
->Close(hDevice
);
785 MixerContext
->Free(PinsRef
);
786 MixerContext
->Free(NodeTypes
);
787 MixerContext
->Free(NodeConnections
);
788 MixerContext
->Free(PinConnectionIndex
);
789 MixerContext
->Free(MixerControls
);
790 MixerContext
->Free(PinsSrcRef
);
794 /* add pins from target line */
797 // dont add bridge pin for input mixers
798 PinsSrcRef
[Index
] = TRUE
;
799 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
801 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
803 Status
= MMixerAddMixerSourceLines(MixerContext
, MixerInfo
, hDevice
, NodeConnections
, NodeTypes
, PinsRefCount
, OutConnection
->Pin
, Index
, PinsSrcRef
);
805 MixerContext
->Free(MixerControls
);
806 MixerContext
->Free(PinsSrcRef
);
815 MMixerInitializeFilter(
816 IN PMIXER_CONTEXT MixerContext
,
817 IN PMIXER_LIST MixerList
,
819 IN LPWSTR DeviceName
,
820 IN PKSMULTIPLE_ITEM NodeTypes
,
821 IN PKSMULTIPLE_ITEM NodeConnections
,
824 IN ULONG bInputMixer
)
826 LPMIXER_INFO MixerInfo
;
828 PKSPIN_PHYSICALCONNECTION OutConnection
;
834 LPWSTR Buffer
= NULL
;
836 // allocate a mixer info struct
837 MixerInfo
= (LPMIXER_INFO
) MixerContext
->Alloc(sizeof(MIXER_INFO
));
841 return MM_STATUS_NO_MEMORY
;
844 // intialize mixer caps */
845 MixerInfo
->MixCaps
.wMid
= MM_MICROSOFT
; //FIXME
846 MixerInfo
->MixCaps
.wPid
= MM_PID_UNMAPPED
; //FIXME
847 MixerInfo
->MixCaps
.vDriverVersion
= 1; //FIXME
848 MixerInfo
->MixCaps
.fdwSupport
= 0;
849 MixerInfo
->MixCaps
.cDestinations
= 1;
850 MixerInfo
->hMixer
= hMixer
;
852 // initialize line list
853 InitializeListHead(&MixerInfo
->LineList
);
855 /* FIXME find mixer name */
857 // now allocate an array which will receive the indices of the pin
858 // which has a ADC / DAC nodetype in its path
859 Pins
= (PULONG
)MixerContext
->Alloc(PinCount
* sizeof(ULONG
));
864 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
865 return MM_STATUS_NO_MEMORY
;
868 // now get the target pins of the ADC / DAC node
869 Status
= MMixerGetTargetPins(MixerContext
, NodeTypes
, NodeConnections
, NodeIndex
, !bInputMixer
, Pins
, PinCount
);
871 for(Index
= 0; Index
< PinCount
; Index
++)
875 /* retrieve pin name */
878 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
879 Pin
.Property
.Set
= KSPROPSETID_Pin
;
880 Pin
.Property
.Id
= KSPROPERTY_PIN_NAME
;
882 /* try get pin name size */
883 Status
= MixerContext
->Control(hMixer
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), NULL
, 0, &BytesReturned
);
885 if (Status
== MM_STATUS_MORE_ENTRIES
)
887 Buffer
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
890 /* try get pin name */
891 Status
= MixerContext
->Control(hMixer
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (PVOID
)Buffer
, BytesReturned
, &BytesReturned
);
892 if (Status
!= MM_STATUS_SUCCESS
)
894 MixerContext
->Free((PVOID
)Buffer
);
907 Status
= MMixerCreateDestinationLine(MixerContext
, MixerInfo
, bInputMixer
, Buffer
);
912 MixerContext
->Free(Buffer
);
915 if (Status
!= MM_STATUS_SUCCESS
)
917 // failed to create destination line
918 MixerContext
->Free(MixerInfo
);
919 MixerContext
->Free(Pins
);
924 RtlZeroMemory(Pins
, sizeof(ULONG
) * PinCount
);
925 // now get the target pins of the ADC / DAC node
926 Status
= MMixerGetTargetPins(MixerContext
, NodeTypes
, NodeConnections
, NodeIndex
, bInputMixer
, Pins
, PinCount
);
928 if (Status
!= MM_STATUS_SUCCESS
)
930 // failed to locate target pins
931 MixerContext
->Free(Pins
);
932 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
933 DPRINT("MMixerGetTargetPins failed with %u\n", Status
);
937 // filter hasnt been used
940 // now check all pins and generate new lines for destination lines
941 for(Index
= 0; Index
< PinCount
; Index
++)
943 DPRINT("Index %lu TargetPin %lu\n", Index
, Pins
[Index
]);
944 // is the current index a target pin
947 // check if the pin has a physical connection
948 Status
= MMixerGetPhysicalConnection(MixerContext
, hMixer
, Index
, &OutConnection
);
949 if (Status
== MM_STATUS_SUCCESS
)
951 // the pin has a physical connection
952 Status
= MMixerHandlePhysicalConnection(MixerContext
, MixerInfo
, bInputMixer
, OutConnection
);
953 DPRINT("MMixerHandlePhysicalConnection status %u\n", Status
);
954 MixerContext
->Free(OutConnection
);
959 // filter exposes the topology on the same filter
960 MMixerAddMixerSourceLine(MixerContext
, MixerInfo
, hMixer
, NodeConnections
, NodeTypes
, Index
, FALSE
, FALSE
);
965 MixerContext
->Free(Pins
);
969 // store mixer info in list
970 if (!bInputMixer
&& MixerList
->MixerListCount
== 1)
972 //FIXME preferred device should be inserted at front
973 //windows always inserts output mixer in front
974 InsertHeadList(&MixerList
->MixerList
, &MixerInfo
->Entry
);
978 InsertTailList(&MixerList
->MixerList
, &MixerInfo
->Entry
);
980 MixerList
->MixerListCount
++;
981 DPRINT("New MixerCount %lu\n", MixerList
->MixerListCount
);
985 // failed to create a mixer topology
986 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
995 IN PMIXER_CONTEXT MixerContext
,
996 IN PMIXER_LIST MixerList
,
998 IN PULONG DeviceCount
,
999 IN LPWSTR DeviceName
)
1001 PKSMULTIPLE_ITEM NodeTypes
, NodeConnections
;
1002 MIXER_STATUS Status
;
1006 // get number of pins
1007 PinCount
= MMixerGetFilterPinCount(MixerContext
, hMixer
);
1009 DPRINT("NumOfPins: %lu\n", PinCount
);
1011 // get filter node types
1012 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hMixer
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
1013 if (Status
!= MM_STATUS_SUCCESS
)
1019 // get filter node connections
1020 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hMixer
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
1021 if (Status
!= MM_STATUS_SUCCESS
)
1024 MixerContext
->Free(NodeTypes
);
1028 // check if the filter has an wave out node
1029 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_DAC
);
1030 if (NodeIndex
!= MAXULONG
)
1033 Status
= MMixerInitializeFilter(MixerContext
, MixerList
, hMixer
, DeviceName
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, FALSE
);
1034 DPRINT("MMixerInitializeFilter Status %u\n", Status
);
1035 // check for success
1036 if (Status
== MM_STATUS_SUCCESS
)
1038 // increment mixer count
1044 // check if the filter has an wave in node
1045 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_ADC
);
1046 if (NodeIndex
!= MAXULONG
)
1049 Status
= MMixerInitializeFilter(MixerContext
, MixerList
, hMixer
, DeviceName
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, TRUE
);
1050 DPRINT("MMixerInitializeFilter Status %u\n", Status
);
1051 // check for success
1052 if (Status
== MM_STATUS_SUCCESS
)
1054 // increment mixer count
1061 MixerContext
->Free((PVOID
)NodeTypes
);
1062 MixerContext
->Free((PVOID
)NodeConnections
);