Amendment to r44518: changing a debug print in LdrpGetOrLoadModule wasn't part of...
[reactos.git] / reactos / lib / drivers / sound / mmixer / controls.c
1 /*
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
7 */
8
9 #include "priv.h"
10
11 MIXER_STATUS
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,
18 OUT PULONG Pins)
19 {
20 PKSTOPOLOGY_CONNECTION Connection;
21 ULONG PinId, NodeConnectionCount, Index;
22 PULONG NodeConnection;
23 MIXER_STATUS Status;
24
25
26 /* sanity check */
27 ASSERT(NodeConnectionIndex < NodeConnections->Count);
28
29 Connection = (PKSTOPOLOGY_CONNECTION)(NodeConnections + 1);
30
31 //DPRINT("FromNode %u FromNodePin %u -> ToNode %u ToNodePin %u\n", Connection[NodeConnectionIndex].FromNode, Connection[NodeConnectionIndex].FromNodePin, Connection[NodeConnectionIndex].ToNode, Connection[NodeConnectionIndex].ToNodePin );
32
33 if ((Connection[NodeConnectionIndex].ToNode == KSFILTER_NODE && bUpDirection == FALSE) ||
34 (Connection[NodeConnectionIndex].FromNode == KSFILTER_NODE && bUpDirection == TRUE))
35 {
36 /* iteration stops here */
37 if (bUpDirection)
38 PinId = Connection[NodeConnectionIndex].FromNodePin;
39 else
40 PinId = Connection[NodeConnectionIndex].ToNodePin;
41
42 //DPRINT("GetTargetPinsByNodeIndex FOUND Target Pin %u Parsed %u\n", PinId, Pins[PinId]);
43
44 /* mark pin index as a target pin */
45 Pins[PinId] = TRUE;
46 return MM_STATUS_SUCCESS;
47 }
48
49 // get all node indexes referenced by that node
50 if (bUpDirection)
51 {
52 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, Connection[NodeConnectionIndex].FromNode, TRUE, FALSE, &NodeConnectionCount, &NodeConnection);
53 }
54 else
55 {
56 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, Connection[NodeConnectionIndex].ToNode, TRUE, TRUE, &NodeConnectionCount, &NodeConnection);
57 }
58
59 if (Status == MM_STATUS_SUCCESS)
60 {
61 for(Index = 0; Index < NodeConnectionCount; Index++)
62 {
63 // iterate recursively into the nodes
64 Status = MMixerGetTargetPinsByNodeConnectionIndex(MixerContext, NodeConnections, NodeTypes, bUpDirection, NodeConnection[Index], Pins);
65 ASSERT(Status == MM_STATUS_SUCCESS);
66 }
67 // free node connection indexes
68 MixerContext->Free(NodeConnection);
69 }
70
71 return Status;
72 }
73
74 MIXER_STATUS
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,
81 OUT PULONG Nodes)
82 {
83 PKSTOPOLOGY_CONNECTION CurConnection;
84 LPGUID NodeType;
85 ULONG NodeIndex;
86 MIXER_STATUS Status;
87 ULONG NodeConnectionCount, Index;
88 PULONG NodeConnection;
89
90
91 /* get current connection */
92 CurConnection = MMixerGetConnectionByIndex(NodeConnections, NodeConnectionIndex);
93
94 if (bUpDirection)
95 NodeIndex = CurConnection->FromNode;
96 else
97 NodeIndex = CurConnection->ToNode;
98
99 /* get target node type of current connection */
100 NodeType = MMixerGetNodeType(NodeTypes, NodeIndex);
101
102 if (IsEqualGUIDAligned(NodeType, &KSNODETYPE_SUM) || IsEqualGUIDAligned(NodeType, &KSNODETYPE_MUX))
103 {
104 if (bUpDirection)
105 {
106 /* add the sum / mux node to destination line */
107 Nodes[NodeIndex] = TRUE;
108 }
109
110 return MM_STATUS_SUCCESS;
111 }
112
113 /* now add the node */
114 Nodes[NodeIndex] = TRUE;
115
116
117 /* get all node indexes referenced by that node */
118 if (bUpDirection)
119 {
120 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, NodeIndex, TRUE, FALSE, &NodeConnectionCount, &NodeConnection);
121 }
122 else
123 {
124 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, NodeIndex, TRUE, TRUE, &NodeConnectionCount, &NodeConnection);
125 }
126
127 if (Status != MM_STATUS_SUCCESS)
128 {
129 for(Index = 0; Index < NodeConnectionCount; Index++)
130 {
131 /* iterate recursively into the nodes */
132 Status = MMixerGetControlsFromPinByConnectionIndex(MixerContext, NodeConnections, NodeTypes, bUpDirection, NodeConnection[Index], Nodes);
133 ASSERT(Status == MM_STATUS_SUCCESS);
134 }
135 /* free node connection indexes */
136 MixerContext->Free(NodeConnection);
137 }
138
139 return Status;
140 }
141
142 MIXER_STATUS
143 MMixerAddMixerControl(
144 IN PMIXER_CONTEXT MixerContext,
145 IN LPMIXER_INFO MixerInfo,
146 IN HANDLE hDevice,
147 IN PKSMULTIPLE_ITEM NodeTypes,
148 IN ULONG NodeIndex,
149 IN LPMIXERLINE_EXT MixerLine,
150 OUT LPMIXERCONTROLW MixerControl)
151 {
152 LPGUID NodeType;
153 KSP_NODE Node;
154 ULONG BytesReturned;
155 MIXER_STATUS Status;
156 LPWSTR Name;
157
158 /* initialize mixer control */
159 MixerControl->cbStruct = sizeof(MIXERCONTROLW);
160 MixerControl->dwControlID = MixerInfo->ControlId;
161
162 /* get node type */
163 NodeType = MMixerGetNodeType(NodeTypes, NodeIndex);
164 /* store control type */
165 MixerControl->dwControlType = MMixerGetControlTypeFromTopologyNode(NodeType);
166
167 MixerControl->fdwControl = MIXERCONTROL_CONTROLF_UNIFORM; //FIXME
168 MixerControl->cMultipleItems = 0; //FIXME
169
170 if (MixerControl->dwControlType == MIXERCONTROL_CONTROLTYPE_MUTE)
171 {
172 MixerControl->Bounds.dwMinimum = 0;
173 MixerControl->Bounds.dwMaximum = 1;
174 }
175 else if (MixerControl->dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME)
176 {
177 MixerControl->Bounds.dwMinimum = 0;
178 MixerControl->Bounds.dwMaximum = 0xFFFF;
179 MixerControl->Metrics.cSteps = 0xC0; //FIXME
180 }
181
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;
187 Node.Reserved = 0;
188
189 /* get node name size */
190 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Node, sizeof(KSP_NODE), NULL, 0, &BytesReturned);
191
192 if (Status == MM_STATUS_MORE_ENTRIES)
193 {
194 ASSERT(BytesReturned != 0);
195 Name = (LPWSTR)MixerContext->Alloc(BytesReturned);
196 if (!Name)
197 {
198 /* not enough memory */
199 return MM_STATUS_NO_MEMORY;
200 }
201
202 /* get node name */
203 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Node, sizeof(KSP_NODE), (LPVOID)Name, BytesReturned, &BytesReturned);
204 if (Status != MM_STATUS_SUCCESS)
205 {
206 MixerContext->Copy(MixerControl->szShortName, Name, (min(MIXER_SHORT_NAME_CHARS, wcslen(Name)+1)) * sizeof(WCHAR));
207 MixerControl->szShortName[MIXER_SHORT_NAME_CHARS-1] = L'\0';
208
209 MixerContext->Copy(MixerControl->szName, Name, (min(MIXER_LONG_NAME_CHARS, wcslen(Name)+1)) * sizeof(WCHAR));
210 MixerControl->szName[MIXER_LONG_NAME_CHARS-1] = L'\0';
211 }
212
213 /* free name buffer */
214 MixerContext->Free(Name);
215 }
216
217 MixerInfo->ControlId++;
218 #if 0
219 if (MixerControl->dwControlType == MIXERCONTROL_CONTROLTYPE_MUX)
220 {
221 KSNODEPROPERTY Property;
222 ULONG PinId = 2;
223
224 /* setup the request */
225 RtlZeroMemory(&Property, sizeof(KSNODEPROPERTY));
226
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;
231
232 /* get node volume level info */
233 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Property, sizeof(KSNODEPROPERTY), (PVOID)&PinId, sizeof(ULONG), &BytesReturned);
234
235 DPRINT1("Status %x NodeIndex %u PinId %u\n", Status, NodeIndex, PinId);
236 //DbgBreakPoint();
237 }else
238 #endif
239 if (MixerControl->dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME)
240 {
241 KSNODEPROPERTY_AUDIO_CHANNEL Property;
242 ULONG Length;
243 PKSPROPERTY_DESCRIPTION Desc;
244 PKSPROPERTY_MEMBERSHEADER Members;
245 PKSPROPERTY_STEPPING_LONG Range;
246
247 Length = sizeof(KSPROPERTY_DESCRIPTION) + sizeof(KSPROPERTY_MEMBERSHEADER) + sizeof(KSPROPERTY_STEPPING_LONG);
248 Desc = (PKSPROPERTY_DESCRIPTION)MixerContext->Alloc(Length);
249 ASSERT(Desc);
250
251 /* setup the request */
252 RtlZeroMemory(&Property, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL));
253
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;
258
259 /* get node volume level info */
260 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Property, sizeof(KSNODEPROPERTY_AUDIO_CHANNEL), Desc, Length, &BytesReturned);
261
262 if (Status == MM_STATUS_SUCCESS)
263 {
264 LPMIXERVOLUME_DATA VolumeData;
265 ULONG Steps, MaxRange, Index;
266 LONG Value;
267
268 Members = (PKSPROPERTY_MEMBERSHEADER)(Desc + 1);
269 Range = (PKSPROPERTY_STEPPING_LONG)(Members + 1);
270
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);
272
273 MaxRange = Range->Bounds.UnsignedMaximum - Range->Bounds.UnsignedMinimum;
274
275 if (MaxRange)
276 {
277 ASSERT(MaxRange);
278 VolumeData = (LPMIXERVOLUME_DATA)MixerContext->Alloc(sizeof(MIXERVOLUME_DATA));
279 if (!VolumeData)
280 return MM_STATUS_NO_MEMORY;
281
282 Steps = MaxRange / Range->SteppingDelta + 1;
283
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;
291
292 VolumeData->Values = (PLONG)MixerContext->Alloc(sizeof(LONG) * Steps);
293 if (!VolumeData->Values)
294 {
295 MixerContext->Free(Desc);
296 MixerContext->Free(VolumeData);
297
298 return MM_STATUS_NO_MEMORY;
299 }
300
301 Value = Range->Bounds.SignedMinimum;
302 for(Index = 0; Index < Steps; Index++)
303 {
304 VolumeData->Values[Index] = Value;
305 Value += Range->SteppingDelta;
306 }
307 InsertTailList(&MixerLine->LineControlsExtraData, &VolumeData->Header.Entry);
308 }
309 }
310 MixerContext->Free(Desc);
311 }
312
313
314 DPRINT("Status %x Name %S\n", Status, MixerControl->szName);
315 return MM_STATUS_SUCCESS;
316 }
317
318 MIXER_STATUS
319 MMixerAddMixerSourceLine(
320 IN PMIXER_CONTEXT MixerContext,
321 IN OUT LPMIXER_INFO MixerInfo,
322 IN HANDLE hDevice,
323 IN PKSMULTIPLE_ITEM NodeConnections,
324 IN PKSMULTIPLE_ITEM NodeTypes,
325 IN ULONG PinId,
326 IN ULONG bBridgePin,
327 IN ULONG bTargetPin)
328 {
329 LPMIXERLINE_EXT SrcLine, DstLine;
330 MIXER_STATUS Status;
331 KSP_PIN Pin;
332 LPWSTR PinName;
333 GUID NodeType;
334 ULONG BytesReturned, ControlCount, Index;
335 PULONG Nodes;
336
337 if (!bTargetPin)
338 {
339 /* allocate src mixer line */
340 SrcLine = (LPMIXERLINE_EXT)MixerContext->Alloc(sizeof(MIXERLINE_EXT));
341
342 if (!SrcLine)
343 return MM_STATUS_NO_MEMORY;
344
345 /* zero struct */
346 RtlZeroMemory(SrcLine, sizeof(MIXERLINE_EXT));
347
348 }
349 else
350 {
351 ASSERT(!IsListEmpty(&MixerInfo->LineList));
352 SrcLine = MMixerGetSourceMixerLineByLineId(MixerInfo, DESTINATION_LINE);
353 }
354
355 /* get destination line */
356 DstLine = MMixerGetSourceMixerLineByLineId(MixerInfo, DESTINATION_LINE);
357 ASSERT(DstLine);
358
359
360 if (!bTargetPin)
361 {
362 /* initialize mixer src line */
363 SrcLine->hDevice = hDevice;
364 SrcLine->PinId = PinId;
365 SrcLine->Line.cbStruct = sizeof(MIXERLINEW);
366
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);
383
384 }
385
386 /* allocate a node arrary */
387 Nodes = (PULONG)MixerContext->Alloc(sizeof(ULONG) * NodeTypes->Count);
388
389 if (!Nodes)
390 {
391 /* not enough memory */
392 if (!bTargetPin)
393 {
394 MixerContext->Free(SrcLine);
395 }
396 return MM_STATUS_NO_MEMORY;
397 }
398
399 Status = MMixerGetControlsFromPin(MixerContext, NodeConnections, NodeTypes, PinId, bTargetPin, Nodes);
400 if (Status != MM_STATUS_SUCCESS)
401 {
402 /* something went wrong */
403 if (!bTargetPin)
404 {
405 MixerContext->Free(SrcLine);
406 }
407 MixerContext->Free(Nodes);
408 return Status;
409 }
410
411 /* now count all nodes controlled by that pin */
412 ControlCount = 0;
413 for(Index = 0; Index < NodeTypes->Count; Index++)
414 {
415 if (Nodes[Index])
416 ControlCount++;
417 }
418
419 /* now allocate the line controls */
420 if (ControlCount)
421 {
422 SrcLine->LineControls = (LPMIXERCONTROLW)MixerContext->Alloc(sizeof(MIXERCONTROLW) * ControlCount);
423
424 if (!SrcLine->LineControls)
425 {
426 /* no memory available */
427 if (!bTargetPin)
428 {
429 MixerContext->Free(SrcLine);
430 }
431 MixerContext->Free(Nodes);
432 return MM_STATUS_NO_MEMORY;
433 }
434
435 SrcLine->NodeIds = (PULONG)MixerContext->Alloc(sizeof(ULONG) * ControlCount);
436 if (!SrcLine->NodeIds)
437 {
438 /* no memory available */
439 MixerContext->Free(SrcLine->LineControls);
440 if (!bTargetPin)
441 {
442 MixerContext->Free(SrcLine);
443 }
444 MixerContext->Free(Nodes);
445 return MM_STATUS_NO_MEMORY;
446 }
447
448 /* zero line controls */
449 RtlZeroMemory(SrcLine->LineControls, sizeof(MIXERCONTROLW) * ControlCount);
450 RtlZeroMemory(SrcLine->NodeIds, sizeof(ULONG) * ControlCount);
451
452 ControlCount = 0;
453 for(Index = 0; Index < NodeTypes->Count; Index++)
454 {
455 if (Nodes[Index])
456 {
457 /* store the node index for retrieving / setting details */
458 SrcLine->NodeIds[ControlCount] = Index;
459
460 Status = MMixerAddMixerControl(MixerContext, MixerInfo, hDevice, NodeTypes, Index, SrcLine, &SrcLine->LineControls[ControlCount]);
461 if (Status != MM_STATUS_SUCCESS)
462 {
463 /* increment control count on success */
464 ControlCount++;
465 }
466 }
467 }
468 /* store control count */
469 SrcLine->Line.cControls = ControlCount;
470 }
471
472 /* release nodes array */
473 MixerContext->Free(Nodes);
474
475 /* get pin category */
476 Pin.PinId = PinId;
477 Pin.Reserved = 0;
478 Pin.Property.Flags = KSPROPERTY_TYPE_GET;
479 Pin.Property.Set = KSPROPSETID_Pin;
480 Pin.Property.Id = KSPROPERTY_PIN_CATEGORY;
481
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)
485 {
486 //FIXME
487 //map component type
488 }
489
490 /* retrieve pin name */
491 Pin.PinId = PinId;
492 Pin.Reserved = 0;
493 Pin.Property.Flags = KSPROPERTY_TYPE_GET;
494 Pin.Property.Set = KSPROPSETID_Pin;
495 Pin.Property.Id = KSPROPERTY_PIN_NAME;
496
497 /* try get pin name size */
498 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSP_PIN), NULL, 0, &BytesReturned);
499
500 if (Status != STATUS_MORE_ENTRIES)
501 {
502 SrcLine->Line.szShortName[0] = L'\0';
503 SrcLine->Line.szName[0] = L'\0';
504 }
505 else
506 {
507 PinName = (LPWSTR)MixerContext->Alloc(BytesReturned);
508 if (PinName)
509 {
510 /* try get pin name */
511 Status = MixerContext->Control(hDevice, IOCTL_KS_PROPERTY, (PVOID)&Pin, sizeof(KSP_PIN), (LPVOID)PinName, BytesReturned, &BytesReturned);
512
513 if (Status != MM_STATUS_SUCCESS)
514 {
515 MixerContext->Copy(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';
517
518 MixerContext->Copy(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';
520 }
521 MixerContext->Free(PinName);
522 }
523 }
524
525 /* insert src line */
526 if (!bTargetPin)
527 {
528 InsertTailList(&MixerInfo->LineList, &SrcLine->Entry);
529 DstLine->Line.cConnections++;
530 }
531
532 return MM_STATUS_SUCCESS;
533 }
534
535 MIXER_STATUS
536 MMixerCreateDestinationLine(
537 IN PMIXER_CONTEXT MixerContext,
538 IN LPMIXER_INFO MixerInfo,
539 IN ULONG bInputMixer)
540 {
541 LPMIXERLINE_EXT DestinationLine;
542
543 // allocate a mixer destination line
544 DestinationLine = (LPMIXERLINE_EXT) MixerContext->Alloc(sizeof(MIXERLINE_EXT));
545 if (!MixerInfo)
546 {
547 // no memory
548 return MM_STATUS_NO_MEMORY;
549 }
550
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);
567
568
569 // insert into mixer info
570 InsertHeadList(&MixerInfo->LineList, &DestinationLine->Entry);
571
572 // done
573 return MM_STATUS_SUCCESS;
574 }
575
576 MIXER_STATUS
577 MMixerGetControlsFromPin(
578 IN PMIXER_CONTEXT MixerContext,
579 IN PKSMULTIPLE_ITEM NodeConnections,
580 IN PKSMULTIPLE_ITEM NodeTypes,
581 IN ULONG PinId,
582 IN ULONG bUpDirection,
583 OUT PULONG Nodes)
584 {
585 ULONG NodeConnectionCount, Index;
586 MIXER_STATUS Status;
587 PULONG NodeConnection;
588
589 /* sanity check */
590 ASSERT(PinId != (ULONG)-1);
591
592 /* get all node indexes referenced by that pin */
593 if (bUpDirection)
594 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, PinId, FALSE, FALSE, &NodeConnectionCount, &NodeConnection);
595 else
596 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, PinId, FALSE, TRUE, &NodeConnectionCount, &NodeConnection);
597
598 for(Index = 0; Index < NodeConnectionCount; Index++)
599 {
600 /* get all associated controls */
601 Status = MMixerGetControlsFromPinByConnectionIndex(MixerContext, NodeConnections, NodeTypes, bUpDirection, NodeConnection[Index], Nodes);
602 }
603
604 MixerContext->Free(NodeConnection);
605
606 return Status;
607 }
608
609
610
611
612 MIXER_STATUS
613 MMixerAddMixerSourceLines(
614 IN PMIXER_CONTEXT MixerContext,
615 IN OUT LPMIXER_INFO MixerInfo,
616 IN HANDLE hDevice,
617 IN PKSMULTIPLE_ITEM NodeConnections,
618 IN PKSMULTIPLE_ITEM NodeTypes,
619 IN ULONG PinsCount,
620 IN ULONG BridgePinIndex,
621 IN ULONG TargetPinIndex,
622 IN PULONG Pins)
623 {
624 ULONG Index;
625
626 for(Index = PinsCount; Index > 0; Index--)
627 {
628 if (Pins[Index-1])
629 {
630 MMixerAddMixerSourceLine(MixerContext, MixerInfo, hDevice, NodeConnections, NodeTypes, Index-1, (Index -1 == BridgePinIndex), (Index -1 == TargetPinIndex));
631 }
632 }
633 return MM_STATUS_SUCCESS;
634 }
635
636
637 MIXER_STATUS
638 MMixerHandlePhysicalConnection(
639 IN PMIXER_CONTEXT MixerContext,
640 IN OUT LPMIXER_INFO MixerInfo,
641 IN ULONG bInput,
642 IN PKSPIN_PHYSICALCONNECTION OutConnection)
643 {
644 PULONG PinsRef = NULL, PinConnectionIndex = NULL, PinsSrcRef;
645 ULONG PinsRefCount, Index, PinConnectionIndexCount;
646 MIXER_STATUS Status;
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;
653
654
655 // open the connected filter
656 Status = MixerContext->Open(OutConnection->SymbolicLinkName, &hDevice);
657 if (Status != MM_STATUS_SUCCESS)
658 {
659 DPRINT1("OpenDevice failed with %x\n", Status);
660 return Status;
661 }
662
663 // get connected filter pin count
664 PinsRefCount = MMixerGetFilterPinCount(MixerContext, hDevice);
665 ASSERT(PinsRefCount);
666
667 PinsRef = (PULONG)MixerContext->Alloc(sizeof(ULONG) * PinsRefCount);
668 if (!PinsRef)
669 {
670 // no memory
671 MixerContext->Close(hDevice);
672 return MM_STATUS_UNSUCCESSFUL;
673 }
674
675 // get topology node types
676 Status = MMixerGetFilterTopologyProperty(MixerContext, hDevice, KSPROPERTY_TOPOLOGY_NODES, &NodeTypes);
677 if (Status != MM_STATUS_SUCCESS)
678 {
679 MixerContext->Close(hDevice);
680 MixerContext->Free(PinsRef);
681 return Status;
682 }
683
684 // get topology connections
685 Status = MMixerGetFilterTopologyProperty(MixerContext, hDevice, KSPROPERTY_TOPOLOGY_CONNECTIONS, &NodeConnections);
686 if (Status != MM_STATUS_SUCCESS)
687 {
688 MixerContext->Close(hDevice);
689 MixerContext->Free(PinsRef);
690 MixerContext->Free(NodeTypes);
691 return Status;
692 }
693 // gets connection index of the bridge pin which connects to a node
694 DPRINT("Pin %u\n", OutConnection->Pin);
695
696 Status = MMixerGetNodeIndexes(MixerContext, NodeConnections, OutConnection->Pin, FALSE, !bInput, &PinConnectionIndexCount, &PinConnectionIndex);
697 if (Status != MM_STATUS_SUCCESS)
698 {
699 MixerContext->Close(hDevice);
700 MixerContext->Free(PinsRef);
701 MixerContext->Free(NodeTypes);
702 MixerContext->Free(NodeConnections);
703 return Status;
704 }
705
706 /* there should be no split in the bride pin */
707 ASSERT(PinConnectionIndexCount == 1);
708
709 /* find all target pins of this connection */
710 Status = MMixerGetTargetPinsByNodeConnectionIndex(MixerContext, NodeConnections, NodeTypes, FALSE, PinConnectionIndex[0], PinsRef);
711 if (Status != MM_STATUS_SUCCESS)
712 {
713 MixerContext->Close(hDevice);
714 MixerContext->Free(PinsRef);
715 MixerContext->Free(NodeTypes);
716 MixerContext->Free(NodeConnections);
717 MixerContext->Free(PinConnectionIndex);
718 return Status;
719 }
720
721 for(Index = 0; Index < PinsRefCount; Index++)
722 {
723 if (PinsRef[Index])
724 {
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)
728 break;
729
730 /* sanity check */
731 ASSERT(MixerControlsCount == 1);
732
733 PinsSrcRef = (PULONG)MixerContext->Alloc(PinsRefCount * sizeof(ULONG));
734 if (!PinsSrcRef)
735 {
736 /* no memory */
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;
744 }
745
746 // now get all connected source pins
747 Status = MMixerGetTargetPinsByNodeConnectionIndex(MixerContext, NodeConnections, NodeTypes, TRUE, MixerControls[0], PinsSrcRef);
748 if (Status != MM_STATUS_SUCCESS)
749 {
750 // failed */
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);
758 return Status;
759 }
760
761 /* add pins from target line */
762 if (!bInput)
763 {
764 // dont add bridge pin for input mixers
765 PinsSrcRef[Index] = TRUE;
766 PinsSrcRef[OutConnection->Pin] = TRUE;
767 }
768 PinsSrcRef[OutConnection->Pin] = TRUE;
769
770 Status = MMixerAddMixerSourceLines(MixerContext, MixerInfo, FileObject, NodeConnections, NodeTypes, PinsRefCount, OutConnection->Pin, Index, PinsSrcRef);
771
772 MixerContext->Free(MixerControls);
773 MixerContext->Free(PinsSrcRef);
774 }
775 }
776
777 return Status;
778 }
779
780
781 MIXER_STATUS
782 MMixerInitializeFilter(
783 IN PMIXER_CONTEXT MixerContext,
784 IN PMIXER_LIST MixerList,
785 IN HANDLE hMixer,
786 IN LPWSTR DeviceName,
787 IN PKSMULTIPLE_ITEM NodeTypes,
788 IN PKSMULTIPLE_ITEM NodeConnections,
789 IN ULONG PinCount,
790 IN ULONG NodeIndex,
791 IN ULONG bInputMixer)
792 {
793 LPMIXER_INFO MixerInfo;
794 MIXER_STATUS Status;
795 PKSPIN_PHYSICALCONNECTION OutConnection;
796 ULONG Index;
797 ULONG * Pins;
798
799 // allocate a mixer info struct
800 MixerInfo = (LPMIXER_INFO) MixerContext->Alloc(sizeof(MIXER_INFO));
801 if (!MixerInfo)
802 {
803 // no memory
804 return MM_STATUS_NO_MEMORY;
805 }
806
807 // intialize mixer caps */
808 MixerInfo->MixCaps.wMid = MM_MICROSOFT; //FIXME
809 MixerInfo->MixCaps.wPid = MM_PID_UNMAPPED; //FIXME
810 MixerInfo->MixCaps.vDriverVersion = 1; //FIXME
811 MixerInfo->MixCaps.fdwSupport = 0;
812 MixerInfo->MixCaps.cDestinations = 1;
813 MixerInfo->hMixer = hMixer;
814
815 // initialize line list
816 InitializeListHead(&MixerInfo->LineList);
817
818 /* FIXME find mixer name */
819
820 Status = MMixerCreateDestinationLine(MixerContext, MixerInfo, bInputMixer);
821 if (Status != MM_STATUS_SUCCESS)
822 {
823 // failed to create destination line
824 MixerContext->Free(MixerInfo);
825 return Status;
826 }
827
828
829 // now allocate an array which will receive the indices of the pin
830 // which has a ADC / DAC nodetype in its path
831 Pins = (PULONG)MixerContext->Alloc(PinCount * sizeof(ULONG));
832
833 if (!Pins)
834 {
835 // no memory
836 MMixerFreeMixerInfo(MixerContext, MixerInfo);
837 return MM_STATUS_NO_MEMORY;
838 }
839
840 // now get the target pins of the ADC / DAC node
841 Status = MMixerGetTargetPins(MixerContext, NodeTypes, NodeConnections, NodeIndex, bInputMixer, Pins, PinCount);
842
843 if (Status != MM_STATUS_SUCCESS)
844 {
845 // failed to locate target pins
846 MixerContext->Free(Pins);
847 MMixerFreeMixerInfo(MixerContext, MixerInfo);
848 return Status;
849 }
850
851 // now check all pins and generate new lines for destination lines
852 for(Index = 0; Index < PinCount; Index++)
853 {
854 // is the current index a target pin
855 if (Pins[Index])
856 {
857 // check if the pin has a physical connection
858 Status = MMixerGetPhysicalConnection(MixerContext, hMixer, Index, &OutConnection);
859 if (Status != MM_STATUS_SUCCESS)
860 {
861 // the pin has a physical connection
862 Status = MMixerHandlePhysicalConnection(MixerContext, MixerInfo, bInputMixer, OutConnection);
863
864 MixerContext->Free(OutConnection);
865 }
866 }
867 }
868 MixerContext->Free(Pins);
869
870 // store mixer info in list
871 InsertTailList(&MixerList->MixerList, &MixerInfo->Entry);
872 MixerList->MixerListCount++;
873
874 // done
875 return Status;
876 }
877
878 MIXER_STATUS
879 MMixerSetupFilter(
880 IN PMIXER_CONTEXT MixerContext,
881 IN PMIXER_LIST MixerList,
882 IN HANDLE hMixer,
883 IN PULONG DeviceCount,
884 IN LPWSTR DeviceName)
885 {
886 PKSMULTIPLE_ITEM NodeTypes, NodeConnections;
887 MIXER_STATUS Status;
888 ULONG PinCount;
889 ULONG NodeIndex;
890
891 // get number of pins
892 PinCount = MMixerGetFilterPinCount(MixerContext, hMixer);
893 ASSERT(PinCount);
894
895
896 // get filter node types
897 Status = MMixerGetFilterTopologyProperty(MixerContext, hMixer, KSPROPERTY_TOPOLOGY_NODES, &NodeTypes);
898 if (Status != MM_STATUS_SUCCESS)
899 {
900 // failed
901 return Status;
902 }
903
904 // get filter node connections
905 Status = MMixerGetFilterTopologyProperty(MixerContext, hMixer, KSPROPERTY_TOPOLOGY_CONNECTIONS, &NodeConnections);
906 if (Status != MM_STATUS_SUCCESS)
907 {
908 // failed
909 MixerContext->Free(NodeTypes);
910 return Status;
911 }
912
913 // check if the filter has an wave out node
914 NodeIndex = MMixerGetIndexOfGuid(NodeTypes, &KSNODETYPE_DAC);
915 if (NodeIndex != MAXULONG)
916 {
917 // it has
918 Status = MMixerInitializeFilter(MixerContext, MixerList, hMixer, DeviceName, NodeTypes, NodeConnections, PinCount, NodeIndex, FALSE);
919
920 // check for success
921 if (Status == MM_STATUS_SUCCESS)
922 {
923 // increment mixer count
924 (*DeviceCount)++;
925 }
926
927 }
928
929 // check if the filter has an wave in node
930 NodeIndex = MMixerGetIndexOfGuid(NodeTypes, &KSNODETYPE_ADC);
931 if (NodeIndex != MAXULONG)
932 {
933 // it has
934 Status = MMixerInitializeFilter(MixerContext, MixerList, hMixer, DeviceName, NodeTypes, NodeConnections, PinCount, NodeIndex, TRUE);
935
936 // check for success
937 if (Status == MM_STATUS_SUCCESS)
938 {
939 // increment mixer count
940 (*DeviceCount)++;
941 }
942
943 }
944
945 //free resources
946 MixerContext->Free((PVOID)NodeTypes);
947 MixerContext->Free((PVOID)NodeConnections);
948
949 // done
950 return Status;
951 }