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 /* get target node type of current connection */
100 NodeType
= MMixerGetNodeType(NodeTypes
, NodeIndex
);
102 if (IsEqualGUIDAligned(NodeType
, &KSNODETYPE_SUM
) || IsEqualGUIDAligned(NodeType
, &KSNODETYPE_MUX
))
106 /* add the sum / mux node to destination line */
107 Nodes
[NodeIndex
] = TRUE
;
110 return MM_STATUS_SUCCESS
;
113 /* now add the node */
114 Nodes
[NodeIndex
] = TRUE
;
117 /* get all node indexes referenced by that node */
120 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, NodeIndex
, TRUE
, FALSE
, &NodeConnectionCount
, &NodeConnection
);
124 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, NodeIndex
, TRUE
, TRUE
, &NodeConnectionCount
, &NodeConnection
);
127 if (Status
!= MM_STATUS_SUCCESS
)
129 for(Index
= 0; Index
< NodeConnectionCount
; Index
++)
131 /* iterate recursively into the nodes */
132 Status
= MMixerGetControlsFromPinByConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, bUpDirection
, NodeConnection
[Index
], Nodes
);
133 ASSERT(Status
== MM_STATUS_SUCCESS
);
135 /* free node connection indexes */
136 MixerContext
->Free(NodeConnection
);
143 MMixerAddMixerControl(
144 IN PMIXER_CONTEXT MixerContext
,
145 IN LPMIXER_INFO MixerInfo
,
147 IN PKSMULTIPLE_ITEM NodeTypes
,
149 IN LPMIXERLINE_EXT MixerLine
,
150 OUT LPMIXERCONTROLW MixerControl
)
158 /* initialize mixer control */
159 MixerControl
->cbStruct
= sizeof(MIXERCONTROLW
);
160 MixerControl
->dwControlID
= MixerInfo
->ControlId
;
163 NodeType
= MMixerGetNodeType(NodeTypes
, NodeIndex
);
164 /* store control type */
165 MixerControl
->dwControlType
= MMixerGetControlTypeFromTopologyNode(NodeType
);
167 MixerControl
->fdwControl
= MIXERCONTROL_CONTROLF_UNIFORM
; //FIXME
168 MixerControl
->cMultipleItems
= 0; //FIXME
170 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_MUTE
)
172 MixerControl
->Bounds
.dwMinimum
= 0;
173 MixerControl
->Bounds
.dwMaximum
= 1;
175 else if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
177 MixerControl
->Bounds
.dwMinimum
= 0;
178 MixerControl
->Bounds
.dwMaximum
= 0xFFFF;
179 MixerControl
->Metrics
.cSteps
= 0xC0; //FIXME
182 /* setup request to retrieve name */
183 Node
.NodeId
= NodeIndex
;
184 Node
.Property
.Id
= KSPROPERTY_TOPOLOGY_NAME
;
185 Node
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
186 Node
.Property
.Set
= KSPROPSETID_Topology
;
189 /* get node name size */
190 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Node
, sizeof(KSP_NODE
), NULL
, 0, &BytesReturned
);
192 if (Status
== MM_STATUS_MORE_ENTRIES
)
194 ASSERT(BytesReturned
!= 0);
195 Name
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
198 /* not enough memory */
199 return MM_STATUS_NO_MEMORY
;
203 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Node
, sizeof(KSP_NODE
), (LPVOID
)Name
, BytesReturned
, &BytesReturned
);
204 if (Status
!= MM_STATUS_SUCCESS
)
206 RtlMoveMemory(MixerControl
->szShortName
, Name
, (min(MIXER_SHORT_NAME_CHARS
, wcslen(Name
)+1)) * sizeof(WCHAR
));
207 MixerControl
->szShortName
[MIXER_SHORT_NAME_CHARS
-1] = L
'\0';
209 RtlMoveMemory(MixerControl
->szName
, Name
, (min(MIXER_LONG_NAME_CHARS
, wcslen(Name
)+1)) * sizeof(WCHAR
));
210 MixerControl
->szName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
213 /* free name buffer */
214 MixerContext
->Free(Name
);
217 MixerInfo
->ControlId
++;
219 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_MUX
)
221 KSNODEPROPERTY Property
;
224 /* setup the request */
225 RtlZeroMemory(&Property
, sizeof(KSNODEPROPERTY
));
227 Property
.NodeId
= NodeIndex
;
228 Property
.Property
.Id
= KSPROPERTY_AUDIO_MUX_SOURCE
;
229 Property
.Property
.Flags
= KSPROPERTY_TYPE_SET
;
230 Property
.Property
.Set
= KSPROPSETID_Audio
;
232 /* get node volume level info */
233 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSNODEPROPERTY
), (PVOID
)&PinId
, sizeof(ULONG
), &BytesReturned
);
235 DPRINT1("Status %x NodeIndex %u PinId %u\n", Status
, NodeIndex
, PinId
);
239 if (MixerControl
->dwControlType
== MIXERCONTROL_CONTROLTYPE_VOLUME
)
241 KSNODEPROPERTY_AUDIO_CHANNEL Property
;
243 PKSPROPERTY_DESCRIPTION Desc
;
244 PKSPROPERTY_MEMBERSHEADER Members
;
245 PKSPROPERTY_STEPPING_LONG Range
;
247 Length
= sizeof(KSPROPERTY_DESCRIPTION
) + sizeof(KSPROPERTY_MEMBERSHEADER
) + sizeof(KSPROPERTY_STEPPING_LONG
);
248 Desc
= (PKSPROPERTY_DESCRIPTION
)MixerContext
->Alloc(Length
);
251 /* setup the request */
252 RtlZeroMemory(&Property
, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL
));
254 Property
.NodeProperty
.NodeId
= NodeIndex
;
255 Property
.NodeProperty
.Property
.Id
= KSPROPERTY_AUDIO_VOLUMELEVEL
;
256 Property
.NodeProperty
.Property
.Flags
= KSPROPERTY_TYPE_BASICSUPPORT
;
257 Property
.NodeProperty
.Property
.Set
= KSPROPSETID_Audio
;
259 /* get node volume level info */
260 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL
), Desc
, Length
, &BytesReturned
);
262 if (Status
== MM_STATUS_SUCCESS
)
264 LPMIXERVOLUME_DATA VolumeData
;
265 ULONG Steps
, MaxRange
, Index
;
268 Members
= (PKSPROPERTY_MEMBERSHEADER
)(Desc
+ 1);
269 Range
= (PKSPROPERTY_STEPPING_LONG
)(Members
+ 1);
271 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
);
273 MaxRange
= Range
->Bounds
.UnsignedMaximum
- Range
->Bounds
.UnsignedMinimum
;
278 VolumeData
= (LPMIXERVOLUME_DATA
)MixerContext
->Alloc(sizeof(MIXERVOLUME_DATA
));
280 return MM_STATUS_NO_MEMORY
;
282 Steps
= MaxRange
/ Range
->SteppingDelta
+ 1;
284 /* store mixer control info there */
285 VolumeData
->Header
.dwControlID
= MixerControl
->dwControlID
;
286 VolumeData
->SignedMaximum
= Range
->Bounds
.SignedMaximum
;
287 VolumeData
->SignedMinimum
= Range
->Bounds
.SignedMinimum
;
288 VolumeData
->SteppingDelta
= Range
->SteppingDelta
;
289 VolumeData
->ValuesCount
= Steps
;
290 VolumeData
->InputSteppingDelta
= 0x10000 / Steps
;
292 VolumeData
->Values
= (PLONG
)MixerContext
->Alloc(sizeof(LONG
) * Steps
);
293 if (!VolumeData
->Values
)
295 MixerContext
->Free(Desc
);
296 MixerContext
->Free(VolumeData
);
298 return MM_STATUS_NO_MEMORY
;
301 Value
= Range
->Bounds
.SignedMinimum
;
302 for(Index
= 0; Index
< Steps
; Index
++)
304 VolumeData
->Values
[Index
] = Value
;
305 Value
+= Range
->SteppingDelta
;
307 InsertTailList(&MixerLine
->LineControlsExtraData
, &VolumeData
->Header
.Entry
);
310 MixerContext
->Free(Desc
);
314 DPRINT("Status %x Name %S\n", Status
, MixerControl
->szName
);
315 return MM_STATUS_SUCCESS
;
319 MMixerAddMixerSourceLine(
320 IN PMIXER_CONTEXT MixerContext
,
321 IN OUT LPMIXER_INFO MixerInfo
,
323 IN PKSMULTIPLE_ITEM NodeConnections
,
324 IN PKSMULTIPLE_ITEM NodeTypes
,
329 LPMIXERLINE_EXT SrcLine
, DstLine
;
334 ULONG BytesReturned
, ControlCount
, Index
;
339 /* allocate src mixer line */
340 SrcLine
= (LPMIXERLINE_EXT
)MixerContext
->Alloc(sizeof(MIXERLINE_EXT
));
343 return MM_STATUS_NO_MEMORY
;
346 RtlZeroMemory(SrcLine
, sizeof(MIXERLINE_EXT
));
351 ASSERT(!IsListEmpty(&MixerInfo
->LineList
));
352 SrcLine
= MMixerGetSourceMixerLineByLineId(MixerInfo
, DESTINATION_LINE
);
355 /* get destination line */
356 DstLine
= MMixerGetSourceMixerLineByLineId(MixerInfo
, DESTINATION_LINE
);
362 /* initialize mixer src line */
363 SrcLine
->hDevice
= hDevice
;
364 SrcLine
->PinId
= PinId
;
365 SrcLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
367 /* initialize mixer destination line */
368 SrcLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
369 SrcLine
->Line
.dwDestination
= 0;
370 SrcLine
->Line
.dwSource
= DstLine
->Line
.cConnections
;
371 SrcLine
->Line
.dwLineID
= (DstLine
->Line
.cConnections
* 0x10000);
372 SrcLine
->Line
.fdwLine
= MIXERLINE_LINEF_ACTIVE
| MIXERLINE_LINEF_SOURCE
;
373 SrcLine
->Line
.dwUser
= 0;
374 SrcLine
->Line
.cChannels
= DstLine
->Line
.cChannels
;
375 SrcLine
->Line
.cConnections
= 0;
376 SrcLine
->Line
.Target
.dwType
= 1;
377 SrcLine
->Line
.Target
.dwDeviceID
= DstLine
->Line
.Target
.dwDeviceID
;
378 SrcLine
->Line
.Target
.wMid
= MixerInfo
->MixCaps
.wMid
;
379 SrcLine
->Line
.Target
.wPid
= MixerInfo
->MixCaps
.wPid
;
380 SrcLine
->Line
.Target
.vDriverVersion
= MixerInfo
->MixCaps
.vDriverVersion
;
381 InitializeListHead(&SrcLine
->LineControlsExtraData
);
382 wcscpy(SrcLine
->Line
.Target
.szPname
, MixerInfo
->MixCaps
.szPname
);
386 /* allocate a node arrary */
387 Nodes
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * NodeTypes
->Count
);
391 /* not enough memory */
394 MixerContext
->Free(SrcLine
);
396 return MM_STATUS_NO_MEMORY
;
399 Status
= MMixerGetControlsFromPin(MixerContext
, NodeConnections
, NodeTypes
, PinId
, bTargetPin
, Nodes
);
400 if (Status
!= MM_STATUS_SUCCESS
)
402 /* something went wrong */
405 MixerContext
->Free(SrcLine
);
407 MixerContext
->Free(Nodes
);
411 /* now count all nodes controlled by that pin */
413 for(Index
= 0; Index
< NodeTypes
->Count
; Index
++)
419 /* now allocate the line controls */
422 SrcLine
->LineControls
= (LPMIXERCONTROLW
)MixerContext
->Alloc(sizeof(MIXERCONTROLW
) * ControlCount
);
424 if (!SrcLine
->LineControls
)
426 /* no memory available */
429 MixerContext
->Free(SrcLine
);
431 MixerContext
->Free(Nodes
);
432 return MM_STATUS_NO_MEMORY
;
435 SrcLine
->NodeIds
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * ControlCount
);
436 if (!SrcLine
->NodeIds
)
438 /* no memory available */
439 MixerContext
->Free(SrcLine
->LineControls
);
442 MixerContext
->Free(SrcLine
);
444 MixerContext
->Free(Nodes
);
445 return MM_STATUS_NO_MEMORY
;
448 /* zero line controls */
449 RtlZeroMemory(SrcLine
->LineControls
, sizeof(MIXERCONTROLW
) * ControlCount
);
450 RtlZeroMemory(SrcLine
->NodeIds
, sizeof(ULONG
) * ControlCount
);
453 for(Index
= 0; Index
< NodeTypes
->Count
; Index
++)
457 /* store the node index for retrieving / setting details */
458 SrcLine
->NodeIds
[ControlCount
] = Index
;
460 Status
= MMixerAddMixerControl(MixerContext
, MixerInfo
, hDevice
, NodeTypes
, Index
, SrcLine
, &SrcLine
->LineControls
[ControlCount
]);
461 if (Status
!= MM_STATUS_SUCCESS
)
463 /* increment control count on success */
468 /* store control count */
469 SrcLine
->Line
.cControls
= ControlCount
;
472 /* release nodes array */
473 MixerContext
->Free(Nodes
);
475 /* get pin category */
478 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
479 Pin
.Property
.Set
= KSPROPSETID_Pin
;
480 Pin
.Property
.Id
= KSPROPERTY_PIN_CATEGORY
;
482 /* try get pin category */
483 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (LPVOID
)&NodeType
, sizeof(GUID
), &BytesReturned
);
484 if (Status
!= MM_STATUS_SUCCESS
)
490 /* retrieve pin name */
493 Pin
.Property
.Flags
= KSPROPERTY_TYPE_GET
;
494 Pin
.Property
.Set
= KSPROPSETID_Pin
;
495 Pin
.Property
.Id
= KSPROPERTY_PIN_NAME
;
497 /* try get pin name size */
498 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), NULL
, 0, &BytesReturned
);
500 if (Status
!= STATUS_MORE_ENTRIES
)
502 SrcLine
->Line
.szShortName
[0] = L
'\0';
503 SrcLine
->Line
.szName
[0] = L
'\0';
507 PinName
= (LPWSTR
)MixerContext
->Alloc(BytesReturned
);
510 /* try get pin name */
511 Status
= MixerContext
->Control(hDevice
, IOCTL_KS_PROPERTY
, (PVOID
)&Pin
, sizeof(KSP_PIN
), (LPVOID
)PinName
, BytesReturned
, &BytesReturned
);
513 if (Status
!= MM_STATUS_SUCCESS
)
515 RtlMoveMemory(SrcLine
->Line
.szShortName
, PinName
, (min(MIXER_SHORT_NAME_CHARS
, wcslen(PinName
)+1)) * sizeof(WCHAR
));
516 SrcLine
->Line
.szShortName
[MIXER_SHORT_NAME_CHARS
-1] = L
'\0';
518 RtlMoveMemory(SrcLine
->Line
.szName
, PinName
, (min(MIXER_LONG_NAME_CHARS
, wcslen(PinName
)+1)) * sizeof(WCHAR
));
519 SrcLine
->Line
.szName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
521 MixerContext
->Free(PinName
);
525 /* insert src line */
528 InsertTailList(&MixerInfo
->LineList
, &SrcLine
->Entry
);
529 DstLine
->Line
.cConnections
++;
532 return MM_STATUS_SUCCESS
;
536 MMixerCreateDestinationLine(
537 IN PMIXER_CONTEXT MixerContext
,
538 IN LPMIXER_INFO MixerInfo
,
539 IN ULONG bInputMixer
)
541 LPMIXERLINE_EXT DestinationLine
;
543 // allocate a mixer destination line
544 DestinationLine
= (LPMIXERLINE_EXT
) MixerContext
->Alloc(sizeof(MIXERLINE_EXT
));
548 return MM_STATUS_NO_MEMORY
;
551 /* initialize mixer destination line */
552 DestinationLine
->Line
.cbStruct
= sizeof(MIXERLINEW
);
553 DestinationLine
->Line
.dwSource
= MAXULONG
;
554 DestinationLine
->Line
.dwLineID
= DESTINATION_LINE
;
555 DestinationLine
->Line
.fdwLine
= MIXERLINE_LINEF_ACTIVE
;
556 DestinationLine
->Line
.dwUser
= 0;
557 DestinationLine
->Line
.dwComponentType
= (bInputMixer
== 0 ? MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
: MIXERLINE_COMPONENTTYPE_DST_WAVEIN
);
558 DestinationLine
->Line
.cChannels
= 2; //FIXME
559 wcscpy(DestinationLine
->Line
.szShortName
, L
"Summe"); //FIXME
560 wcscpy(DestinationLine
->Line
.szName
, L
"Summe"); //FIXME
561 DestinationLine
->Line
.Target
.dwType
= (bInputMixer
== 0 ? MIXERLINE_TARGETTYPE_WAVEOUT
: MIXERLINE_TARGETTYPE_WAVEIN
);
562 DestinationLine
->Line
.Target
.dwDeviceID
= !bInputMixer
;
563 DestinationLine
->Line
.Target
.wMid
= MixerInfo
->MixCaps
.wMid
;
564 DestinationLine
->Line
.Target
.wPid
= MixerInfo
->MixCaps
.wPid
;
565 DestinationLine
->Line
.Target
.vDriverVersion
= MixerInfo
->MixCaps
.vDriverVersion
;
566 wcscpy(DestinationLine
->Line
.Target
.szPname
, MixerInfo
->MixCaps
.szPname
);
569 // insert into mixer info
570 InsertHeadList(&MixerInfo
->LineList
, &DestinationLine
->Entry
);
573 return MM_STATUS_SUCCESS
;
577 MMixerGetControlsFromPin(
578 IN PMIXER_CONTEXT MixerContext
,
579 IN PKSMULTIPLE_ITEM NodeConnections
,
580 IN PKSMULTIPLE_ITEM NodeTypes
,
582 IN ULONG bUpDirection
,
585 ULONG NodeConnectionCount
, Index
;
587 PULONG NodeConnection
;
590 ASSERT(PinId
!= (ULONG
)-1);
592 /* get all node indexes referenced by that pin */
594 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, PinId
, FALSE
, FALSE
, &NodeConnectionCount
, &NodeConnection
);
596 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, PinId
, FALSE
, TRUE
, &NodeConnectionCount
, &NodeConnection
);
598 for(Index
= 0; Index
< NodeConnectionCount
; Index
++)
600 /* get all associated controls */
601 Status
= MMixerGetControlsFromPinByConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, bUpDirection
, NodeConnection
[Index
], Nodes
);
604 MixerContext
->Free(NodeConnection
);
613 MMixerAddMixerSourceLines(
614 IN PMIXER_CONTEXT MixerContext
,
615 IN OUT LPMIXER_INFO MixerInfo
,
617 IN PKSMULTIPLE_ITEM NodeConnections
,
618 IN PKSMULTIPLE_ITEM NodeTypes
,
620 IN ULONG BridgePinIndex
,
621 IN ULONG TargetPinIndex
,
626 for(Index
= PinsCount
; Index
> 0; Index
--)
630 MMixerAddMixerSourceLine(MixerContext
, MixerInfo
, hDevice
, NodeConnections
, NodeTypes
, Index
-1, (Index
-1 == BridgePinIndex
), (Index
-1 == TargetPinIndex
));
633 return MM_STATUS_SUCCESS
;
638 MMixerHandlePhysicalConnection(
639 IN PMIXER_CONTEXT MixerContext
,
640 IN OUT LPMIXER_INFO MixerInfo
,
642 IN PKSPIN_PHYSICALCONNECTION OutConnection
)
644 PULONG PinsRef
= NULL
, PinConnectionIndex
= NULL
, PinsSrcRef
;
645 ULONG PinsRefCount
, Index
, PinConnectionIndexCount
;
647 HANDLE hDevice
= NULL
;
648 PFILE_OBJECT FileObject
= NULL
;
649 PKSMULTIPLE_ITEM NodeTypes
= NULL
;
650 PKSMULTIPLE_ITEM NodeConnections
= NULL
;
651 PULONG MixerControls
;
652 ULONG MixerControlsCount
;
655 // open the connected filter
656 Status
= MixerContext
->Open(OutConnection
->SymbolicLinkName
, &hDevice
);
657 if (Status
!= MM_STATUS_SUCCESS
)
659 DPRINT1("OpenDevice failed with %x\n", Status
);
663 // get connected filter pin count
664 PinsRefCount
= MMixerGetFilterPinCount(MixerContext
, hDevice
);
665 ASSERT(PinsRefCount
);
667 PinsRef
= (PULONG
)MixerContext
->Alloc(sizeof(ULONG
) * PinsRefCount
);
671 MixerContext
->Close(hDevice
);
672 return MM_STATUS_UNSUCCESSFUL
;
675 // get topology node types
676 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hDevice
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
677 if (Status
!= MM_STATUS_SUCCESS
)
679 MixerContext
->Close(hDevice
);
680 MixerContext
->Free(PinsRef
);
684 // get topology connections
685 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hDevice
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
686 if (Status
!= MM_STATUS_SUCCESS
)
688 MixerContext
->Close(hDevice
);
689 MixerContext
->Free(PinsRef
);
690 MixerContext
->Free(NodeTypes
);
693 // gets connection index of the bridge pin which connects to a node
694 DPRINT("Pin %u\n", OutConnection
->Pin
);
696 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, OutConnection
->Pin
, FALSE
, !bInput
, &PinConnectionIndexCount
, &PinConnectionIndex
);
697 if (Status
!= MM_STATUS_SUCCESS
)
699 MixerContext
->Close(hDevice
);
700 MixerContext
->Free(PinsRef
);
701 MixerContext
->Free(NodeTypes
);
702 MixerContext
->Free(NodeConnections
);
706 /* there should be no split in the bride pin */
707 ASSERT(PinConnectionIndexCount
== 1);
709 /* find all target pins of this connection */
710 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, FALSE
, PinConnectionIndex
[0], PinsRef
);
711 if (Status
!= MM_STATUS_SUCCESS
)
713 MixerContext
->Close(hDevice
);
714 MixerContext
->Free(PinsRef
);
715 MixerContext
->Free(NodeTypes
);
716 MixerContext
->Free(NodeConnections
);
717 MixerContext
->Free(PinConnectionIndex
);
721 for(Index
= 0; Index
< PinsRefCount
; Index
++)
725 // found a target pin, now get all references
726 Status
= MMixerGetNodeIndexes(MixerContext
, NodeConnections
, Index
, FALSE
, FALSE
, &MixerControlsCount
, &MixerControls
);
727 if (Status
!= MM_STATUS_SUCCESS
)
731 ASSERT(MixerControlsCount
== 1);
733 PinsSrcRef
= (PULONG
)MixerContext
->Alloc(PinsRefCount
* sizeof(ULONG
));
737 MixerContext
->Close(hDevice
);
738 MixerContext
->Free(PinsRef
);
739 MixerContext
->Free(NodeTypes
);
740 MixerContext
->Free(NodeConnections
);
741 MixerContext
->Free(PinConnectionIndex
);
742 MixerContext
->Free(MixerControls
);
743 return MM_STATUS_NO_MEMORY
;
746 // now get all connected source pins
747 Status
= MMixerGetTargetPinsByNodeConnectionIndex(MixerContext
, NodeConnections
, NodeTypes
, TRUE
, MixerControls
[0], PinsSrcRef
);
748 if (Status
!= MM_STATUS_SUCCESS
)
751 MixerContext
->Close(hDevice
);
752 MixerContext
->Free(PinsRef
);
753 MixerContext
->Free(NodeTypes
);
754 MixerContext
->Free(NodeConnections
);
755 MixerContext
->Free(PinConnectionIndex
);
756 MixerContext
->Free(MixerControls
);
757 MixerContext
->Free(PinsSrcRef
);
761 /* add pins from target line */
764 // dont add bridge pin for input mixers
765 PinsSrcRef
[Index
] = TRUE
;
766 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
768 PinsSrcRef
[OutConnection
->Pin
] = TRUE
;
770 Status
= MMixerAddMixerSourceLines(MixerContext
, MixerInfo
, FileObject
, NodeConnections
, NodeTypes
, PinsRefCount
, OutConnection
->Pin
, Index
, PinsSrcRef
);
772 MixerContext
->Free(MixerControls
);
773 MixerContext
->Free(PinsSrcRef
);
782 MMixerInitializeFilter(
783 IN PMIXER_CONTEXT MixerContext
,
785 IN LPWSTR DeviceName
,
786 IN PKSMULTIPLE_ITEM NodeTypes
,
787 IN PKSMULTIPLE_ITEM NodeConnections
,
790 IN ULONG bInputMixer
)
792 LPMIXER_INFO MixerInfo
;
794 PKSPIN_PHYSICALCONNECTION OutConnection
;
798 // allocate a mixer info struct
799 MixerInfo
= (LPMIXER_INFO
) MixerContext
->Alloc(sizeof(MIXER_INFO
));
803 return MM_STATUS_NO_MEMORY
;
806 // intialize mixer caps */
807 MixerInfo
->MixCaps
.wMid
= MM_MICROSOFT
; //FIXME
808 MixerInfo
->MixCaps
.wPid
= MM_PID_UNMAPPED
; //FIXME
809 MixerInfo
->MixCaps
.vDriverVersion
= 1; //FIXME
810 MixerInfo
->MixCaps
.fdwSupport
= 0;
811 MixerInfo
->MixCaps
.cDestinations
= 1;
812 MixerInfo
->hMixer
= hMixer
;
814 // initialize line list
815 InitializeListHead(&MixerInfo
->LineList
);
817 /* FIXME find mixer name */
819 Status
= MMixerCreateDestinationLine(MixerContext
, MixerInfo
, bInputMixer
);
820 if (Status
!= MM_STATUS_SUCCESS
)
822 // failed to create destination line
823 MixerContext
->Free(MixerInfo
);
828 // now allocate an array which will receive the indices of the pin
829 // which has a ADC / DAC nodetype in its path
830 Pins
= (PULONG
)MixerContext
->Alloc(PinCount
* sizeof(ULONG
));
835 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
836 return MM_STATUS_NO_MEMORY
;
839 // now get the target pins of the ADC / DAC node
840 Status
= MMixerGetTargetPins(MixerContext
, NodeTypes
, NodeConnections
, NodeIndex
, bInputMixer
, Pins
, PinCount
);
842 if (Status
!= MM_STATUS_SUCCESS
)
844 // failed to locate target pins
845 MixerContext
->Free(Pins
);
846 MMixerFreeMixerInfo(MixerContext
, MixerInfo
);
850 // now check all pins and generate new lines for destination lines
851 for(Index
= 0; Index
< PinCount
; Index
++)
853 // is the current index a target pin
856 // check if the pin has a physical connection
857 Status
= MMixerGetPhysicalConnection(MixerContext
, hMixer
, Index
, &OutConnection
);
858 if (Status
!= MM_STATUS_SUCCESS
)
860 // the pin has a physical connection
861 Status
= MMixerHandlePhysicalConnection(MixerContext
, MixerInfo
, bInputMixer
, OutConnection
);
863 MixerContext
->Free(OutConnection
);
867 MixerContext
->Free(Pins
);
870 // store MixerInfo in context
879 IN PMIXER_CONTEXT MixerContext
,
881 IN PULONG DeviceCount
,
882 IN LPWSTR DeviceName
)
884 PKSMULTIPLE_ITEM NodeTypes
, NodeConnections
;
889 // get number of pins
890 PinCount
= MMixerGetFilterPinCount(MixerContext
, hMixer
);
894 // get filter node types
895 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hMixer
, KSPROPERTY_TOPOLOGY_NODES
, &NodeTypes
);
896 if (Status
!= MM_STATUS_SUCCESS
)
902 // get filter node connections
903 Status
= MMixerGetFilterTopologyProperty(MixerContext
, hMixer
, KSPROPERTY_TOPOLOGY_CONNECTIONS
, &NodeConnections
);
904 if (Status
!= MM_STATUS_SUCCESS
)
907 MixerContext
->Free(NodeTypes
);
911 // check if the filter has an wave out node
912 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_DAC
);
913 if (NodeIndex
!= MAXULONG
)
916 Status
= MMixerInitializeFilter(MixerContext
, hMixer
, DeviceName
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, FALSE
);
919 if (Status
== MM_STATUS_SUCCESS
)
921 // increment mixer count
927 // check if the filter has an wave in node
928 NodeIndex
= MMixerGetIndexOfGuid(NodeTypes
, &KSNODETYPE_ADC
);
929 if (NodeIndex
!= MAXULONG
)
932 Status
= MMixerInitializeFilter(MixerContext
, hMixer
, DeviceName
, NodeTypes
, NodeConnections
, PinCount
, NodeIndex
, TRUE
);
935 if (Status
== MM_STATUS_SUCCESS
)
937 // increment mixer count
944 MixerContext
->Free((PVOID
)NodeTypes
);
945 MixerContext
->Free((PVOID
)NodeConnections
);