-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrtsdtopo.cpp
More file actions
571 lines (487 loc) · 17.5 KB
/
rtsdtopo.cpp
File metadata and controls
571 lines (487 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/*
Module Name:
rtsdtopo.cpp
Abstract:
Implementation of topology miniport.
*/
#include "rtsdaudio.h"
#include "common.h"
#include "rtsdwave.h"
#include "rtsdtopo.h"
#include "toptable.h"
/*********************************************************************
* Topology/Wave bridge connection *
* *
* +------+ +------+ *
* | Wave | | Topo | *
* | | | | *
* Capture <---|0 1|<===|4 1|<--- Synth *
* | | | | *
* Render --->|2 3|===>|0 | *
* +------+ | | *
* | 2|<--- Mic *
* | | *
* | 3|---> Line Out *
* +------+ *
*********************************************************************/
PHYSICALCONNECTIONTABLE TopologyPhysicalConnections =
{
KSPIN_TOPO_WAVEOUT_SOURCE, // TopologyIn
KSPIN_TOPO_WAVEIN_DEST, // TopologyOut
KSPIN_WAVE_CAPTURE_SOURCE, // WaveIn
KSPIN_WAVE_RENDER_SOURCE // WaveOut
};
#pragma code_seg("PAGE")
//=============================================================================
NTSTATUS CreateMiniportTopology(
OUT PUNKNOWN * Unknown,
IN REFCLSID,
IN PUNKNOWN UnknownOuter OPTIONAL,
IN POOL_TYPE PoolType
)
/*
Routine Description:
Creates a new topology miniport.
Arguments:
Unknown -
RefclsId -
UnknownOuter -
PoolType -
Return Value:
NT status code.
*/
{
PAGED_CODE();
ASSERT(Unknown);
STD_CREATE_BODY(CMiniportTopology, Unknown, UnknownOuter, PoolType);
}
//=============================================================================
NTSTATUS PropertyHandler_Topology (
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Redirects property request to miniport object
Arguments:
PropertyRequest -
Return Value:
NT status code.
*/
{
PAGED_CODE();
ASSERT(PropertyRequest);
DPF_ENTER(("[PropertyHandler_Topology]"));
// PropertryRequest structure is filled by portcls.
// MajorTarget is a pointer to miniport object for miniports.
return ((PCMiniportTopology)(PropertyRequest->MajorTarget))->PropertyHandlerGeneric(PropertyRequest);
}
//=============================================================================
CMiniportTopology::~CMiniportTopology(void)
/*
Routine Description:
Topology miniport destructor
Arguments:
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::~CMiniportTopology]"));
if (m_AdapterCommon) {
m_AdapterCommon->Release();
}
}
//=============================================================================
NTSTATUS CMiniportTopology::DataRangeIntersection(
IN ULONG PinId,
IN PKSDATARANGE ClientDataRange,
IN PKSDATARANGE MyDataRange,
IN ULONG OutputBufferLength,
OUT PVOID ResultantFormat OPTIONAL,
OUT PULONG ResultantFormatLength
)
/*
Routine Description:
The DataRangeIntersection function determines the highest quality
intersection of two data ranges.
Arguments:
PinId - Pin for which data intersection is being determined.
ClientDataRange - Pointer to KSDATARANGE structure which contains the data range
submitted by client in the data range intersection property
request.
MyDataRange - Pin's data range to be compared with client's data range.
OutputBufferLength - Size of the buffer pointed to by the resultant format
parameter.
ResultantFormat - Pointer to value where the resultant format should be
returned.
ResultantFormatLength - Actual length of the resultant format that is placed
at ResultantFormat. This should be less than or equal
to OutputBufferLength.
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::DataRangeIntersection]"));
return (STATUS_NOT_IMPLEMENTED);
}
//=============================================================================
STDMETHODIMP CMiniportTopology::GetDescription(
OUT PPCFILTER_DESCRIPTOR * OutFilterDescriptor
)
/*
Routine Description:
The GetDescription function gets a pointer to a filter description.
It provides a location to deposit a pointer in miniport's description
structure. This is the placeholder for the FromNode or ToNode fields in
connections which describe connections to the filter's pins.
Arguments:
OutFilterDescriptor - Pointer to the filter description.
Return Value:
NT status code.
*/
{
PAGED_CODE();
ASSERT(OutFilterDescriptor);
DPF_ENTER(("[CMiniportTopology::GetDescription]"));
*OutFilterDescriptor = m_FilterDescriptor;
return (STATUS_SUCCESS);
}
//=============================================================================
STDMETHODIMP CMiniportTopology::Init(
IN PUNKNOWN UnknownAdapter,
IN PRESOURCELIST ResourceList,
IN PPORTTOPOLOGY Port_
)
/*
Routine Description:
The Init function initializes the miniport. Callers of this function
should run at IRQL PASSIVE_LEVEL
Arguments:
UnknownAdapter - A pointer to the Iuknown interface of the adapter object.
ResourceList - Pointer to the resource list to be supplied to the miniport
during initialization. The port driver is free to examine the
contents of the ResourceList. The port driver will not be
modify the ResourceList contents.
Port - Pointer to the topology port object that is linked with this miniport.
Return Value:
NT status code.
*/
{
PAGED_CODE();
ASSERT(UnknownAdapter);
ASSERT(Port_);
DPF_ENTER(("[CMiniportTopology::Init]"));
// aus dem Konstruktor
m_AdapterCommon = NULL;
m_FilterDescriptor = NULL;
NTSTATUS ntStatus;
ntStatus = UnknownAdapter->QueryInterface(
IID_IAdapterCommon,
(PVOID *) &m_AdapterCommon
);
if (NT_SUCCESS(ntStatus)) {
m_AdapterCommon->MixerReset();
}
if (!NT_SUCCESS(ntStatus)) {
// clean up AdapterCommon
if (m_AdapterCommon) {
m_AdapterCommon->Release();
m_AdapterCommon = NULL;
}
}
if (NT_SUCCESS(ntStatus)) {
m_FilterDescriptor = &MiniportFilterDescriptor;
m_AdapterCommon->MixerMuxWrite(KSPIN_TOPO_MIC_SOURCE);
}
return ntStatus;
} // Init
//=============================================================================
STDMETHODIMP CMiniportTopology::NonDelegatingQueryInterface(
IN REFIID Interface,
OUT PVOID * Object
)
/*
Routine Description:
QueryInterface for MiniportTopology
Arguments:
Interface - GUID of the interface
Object - interface object to be returned.
Return Value:
NT status code.
*/
{
PAGED_CODE();
ASSERT(Object);
if (IsEqualGUIDAligned(Interface, IID_IUnknown)) {
*Object = PVOID(PUNKNOWN(this));
} else if (IsEqualGUIDAligned(Interface, IID_IMiniport)) {
*Object = PVOID(PMINIPORT(this));
} else if (IsEqualGUIDAligned(Interface, IID_IMiniportTopology)) {
*Object = PVOID(PMINIPORTTOPOLOGY(this));
} else {
*Object = NULL;
}
if (*Object) {
// We reference the interface for the caller.
PUNKNOWN(*Object)->AddRef();
return(STATUS_SUCCESS);
}
return(STATUS_INVALID_PARAMETER);
} // NonDelegatingQueryInterface
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerGeneric(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Handles all properties for this miniport.
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
switch (PropertyRequest->PropertyItem->Id)
{
case KSPROPERTY_AUDIO_VOLUMELEVEL:
ntStatus = PropertyHandlerVolume(PropertyRequest);
break;
case KSPROPERTY_AUDIO_CPU_RESOURCES:
ntStatus = PropertyHandlerCpuResources(PropertyRequest);
break;
case KSPROPERTY_AUDIO_MUTE:
ntStatus = PropertyHandlerMute(PropertyRequest);
break;
case KSPROPERTY_AUDIO_MUX_SOURCE:
ntStatus = PropertyHandlerMuxSource(PropertyRequest);
break;
default:
DPF(D_TERSE, ("[PropertyHandlerGeneric: Invalid Device Request]"));
}
return ntStatus;
} // PropertyHandlerGeneric
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerBasicSupportVolume(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Handles BasicSupport for Volume nodes.
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_SUCCESS;
ULONG cbFullProperty = sizeof(KSPROPERTY_DESCRIPTION) + sizeof(KSPROPERTY_MEMBERSHEADER) + sizeof(KSPROPERTY_STEPPING_LONG);
if(PropertyRequest->ValueSize >= (sizeof(KSPROPERTY_DESCRIPTION))) {
PKSPROPERTY_DESCRIPTION PropDesc = PKSPROPERTY_DESCRIPTION(PropertyRequest->Value);
PropDesc->AccessFlags = KSPROPERTY_TYPE_ALL;
PropDesc->DescriptionSize = cbFullProperty;
PropDesc->PropTypeSet.Set = KSPROPTYPESETID_General;
PropDesc->PropTypeSet.Id = VT_I4;
PropDesc->PropTypeSet.Flags = 0;
PropDesc->MembersListCount = 1;
PropDesc->Reserved = 0;
// if return buffer can also hold a range description, return it too
if(PropertyRequest->ValueSize >= cbFullProperty) {
// fill in the members header
PKSPROPERTY_MEMBERSHEADER Members = PKSPROPERTY_MEMBERSHEADER(PropDesc + 1);
Members->MembersFlags = KSPROPERTY_MEMBER_STEPPEDRANGES;
Members->MembersSize = sizeof(KSPROPERTY_STEPPING_LONG);
Members->MembersCount = 1;
Members->Flags = 0;
// fill in the stepped range
PKSPROPERTY_STEPPING_LONG Range = PKSPROPERTY_STEPPING_LONG(Members + 1);
// BUGBUG these are from SB16 driver.
// Are these valid.
Range->Bounds.SignedMaximum = 0xE0000; // 14 (dB) * 0x10000
Range->Bounds.SignedMinimum = 0xFFF20000; // -14 (dB) * 0x10000
Range->SteppingDelta = 0x20000; // 2 (dB) * 0x10000
Range->Reserved = 0;
// set the return value size
PropertyRequest->ValueSize = cbFullProperty;
} else {
PropertyRequest->ValueSize = 0;
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
} else if(PropertyRequest->ValueSize >= sizeof(ULONG)) {
// if return buffer can hold a ULONG, return the access flags
PULONG AccessFlags = PULONG(PropertyRequest->Value);
PropertyRequest->ValueSize = sizeof(ULONG);
*AccessFlags = KSPROPERTY_TYPE_ALL;
} else if (PropertyRequest->ValueSize == 0) {
// Send the caller required value size.
PropertyRequest->ValueSize = cbFullProperty;
ntStatus = STATUS_BUFFER_OVERFLOW;
} else {
PropertyRequest->ValueSize = 0;
ntStatus = STATUS_BUFFER_TOO_SMALL;
}
return ntStatus;
} // PropertyHandlerBasicSupportVolume
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerCpuResources(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Processes KSPROPERTY_AUDIO_CPURESOURCES
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::PropertyHandlerCpuResources]"));
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG));
if (NT_SUCCESS(ntStatus)) {
*(PLONG(PropertyRequest->Value)) = KSAUDIO_CPU_RESOURCES_NOT_HOST_CPU;
PropertyRequest->ValueSize = sizeof(LONG);
}
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
ntStatus = PropertyHandler_BasicSupport(
PropertyRequest,
KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_BASICSUPPORT,
VT_ILLEGAL
);
}
return ntStatus;
} // PropertyHandlerCpuResources
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerMute(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Property handler for KSPROPERTY_AUDIO_MUTE
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::PropertyHandlerMute]"));
NTSTATUS ntStatus;
LONG lChannel;
PBOOL pfMute;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
ntStatus = PropertyHandler_BasicSupport(
PropertyRequest,
KSPROPERTY_TYPE_ALL,
VT_BOOL
);
} else {
ntStatus = ValidatePropertyParams(
PropertyRequest,
sizeof(BOOL),
sizeof(LONG)
);
if (NT_SUCCESS(ntStatus)) {
lChannel = * PLONG (PropertyRequest->Instance);
pfMute = PBOOL (PropertyRequest->Value);
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
*pfMute = m_AdapterCommon->MixerMuteRead(PropertyRequest->Node);
PropertyRequest->ValueSize = sizeof(BOOL);
ntStatus = STATUS_SUCCESS;
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
m_AdapterCommon->MixerMuteWrite(PropertyRequest->Node, *pfMute);
ntStatus = STATUS_SUCCESS;
}
} else {
DPF(D_TERSE, ("[PropertyHandlerMute - Invalid parameter]"));
ntStatus = STATUS_INVALID_PARAMETER;
}
}
return ntStatus;
} // PropertyHandlerMute
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerMuxSource(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
PropertyHandler for KSPROPERTY_AUDIO_MUX_SOURCE.
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::PropertyHandlerMuxSource]"));
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
// Validate node
// This property is only valid for WAVEIN_MUX node.
//
// TODO if (WAVEIN_MUX == PropertyRequest->Node)
{
if (PropertyRequest->ValueSize >= sizeof(ULONG)) {
PULONG pulMuxValue = PULONG(PropertyRequest->Value);
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
*pulMuxValue = m_AdapterCommon->MixerMuxRead();
PropertyRequest->ValueSize = sizeof(ULONG);
ntStatus = STATUS_SUCCESS;
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
m_AdapterCommon->MixerMuxWrite(*pulMuxValue);
ntStatus = STATUS_SUCCESS;
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
ntStatus = PropertyHandler_BasicSupport(PropertyRequest, KSPROPERTY_TYPE_ALL, VT_I4);
}
} else {
DPF(D_TERSE, ("[PropertyHandlerMuxSource - Invalid parameter]"));
ntStatus = STATUS_INVALID_PARAMETER;
}
}
return ntStatus;
} // PropertyHandlerMuxSource
//=============================================================================
NTSTATUS CMiniportTopology::PropertyHandlerVolume(
IN PPCPROPERTY_REQUEST PropertyRequest
)
/*
Routine Description:
Property handler for KSPROPERTY_AUDIO_VOLUMELEVEL
Arguments:
PropertyRequest - property request structure
Return Value:
NT status code.
*/
{
PAGED_CODE();
DPF_ENTER(("[CMiniportTopology::PropertyHandlerVolume]"));
NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
LONG lChannel;
PULONG pulVolume;
if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT) {
ntStatus = PropertyHandlerBasicSupportVolume(PropertyRequest);
} else {
ntStatus = ValidatePropertyParams(PropertyRequest, sizeof(ULONG), sizeof(KSNODEPROPERTY_AUDIO_CHANNEL)-sizeof(KSNODEPROPERTY));
if (NT_SUCCESS(ntStatus)) {
lChannel = * (PLONG (PropertyRequest->Instance));
pulVolume = PULONG (PropertyRequest->Value);
if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET) {
*pulVolume = m_AdapterCommon->MixerVolumeRead(PropertyRequest->Node, lChannel);
PropertyRequest->ValueSize = sizeof(ULONG);
ntStatus = STATUS_SUCCESS;
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
m_AdapterCommon->MixerVolumeWrite(PropertyRequest->Node, lChannel, *pulVolume);
ntStatus = STATUS_SUCCESS;
}
} else {
DPF(D_TERSE, ("[PropertyHandlerVolume - Invalid parameter]"));
ntStatus = STATUS_INVALID_PARAMETER;
}
}
return ntStatus;
} // PropertyHandlerVolume
#pragma code_seg()