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
|
/*++
Copyright (c) Microsoft Corporation All Rights Reserved
Module Name:
AudioModule1.h
Abstract:
Declaration of Audio Module 1.
--*/
#ifndef _SYSVAD_AUDIOMODULE1_H_
#define _SYSVAD_AUDIOMODULE1_H_
#include "AudioModuleHelper.h"
#define AUDIOMODULE1_MAJOR 0x2
#define AUDIOMODULE1_MINOR 0X1
static const GUID AudioModule1Id =
{ 0x5ce55c8e, 0x84df, 0x4317, 0x98, 0xc7, 0x79, 0x2d, 0xe8, 0x33, 0x66, 0xcc };
enum AudioModule1_Parameter {
AudioModule1Parameter1 = 0,
AudioModule1Parameter2,
AudioModule1Parameter3
};
typedef struct _AUDIOMODULE1_CUSTOM_COMMAND {
ULONG Verb; // get, set and support
AudioModule1_Parameter ParameterId;
} AUDIOMODULE1_CUSTOM_COMMAND, *PAUDIOMODULE1_CUSTOM_COMMAND;
enum AudioModule1_Notification_Type {
AudioModule1ParameterChanged = 0,
};
typedef struct _AUDIOMODULE1_CUSTOM_NOTIFICATION {
ULONG Type;
union {
struct {
ULONG ParameterId;
} ParameterChanged;
};
} AUDIOMODULE1_CUSTOM_NOTIFICATION, *PAUDIOMODULE1_CUSTOM_NOTIFICATION;
typedef struct _AUDIOMODULE1_NOTIFICATION {
KSAUDIOMODULE_NOTIFICATION Header;
AUDIOMODULE1_CUSTOM_NOTIFICATION CustomNotification;
} AUDIOMODULE1_NOTIFICATION, *PAUDIOMODULE1_NOTIFICATION;
typedef struct _AUDIOMODULE1_CONTEXT {
BYTE Parameter1;
ULONGLONG Parameter2;
DWORD Parameter3;
ULONG InstanceId;
AUDIOMODULE1_NOTIFICATION Notification;
PPORTCLSNOTIFICATIONS PortNotifications;
} AUDIOMODULE1_CONTEXT, *PAUDIOMODULE1_CONTEXT;
static
BYTE AudioModule1_ValidParameter1List[] =
{
0, 1, 2
};
static
AUDIOMODULE_PARAMETER_INFO AudioModule1_ParameterInfo[] =
{
{
KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_BASICSUPPORT,
AUDIOMODULE_PARAMETER_FLAG_CHANGE_NOTIFICATION,
(ULONG)RTL_FIELD_SIZE(AUDIOMODULE1_CONTEXT, Parameter1),
VT_UI1,
AudioModule1_ValidParameter1List,
SIZEOF_ARRAY(AudioModule1_ValidParameter1List)
},
{
KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_BASICSUPPORT,
0,
(ULONG)RTL_FIELD_SIZE(AUDIOMODULE1_CONTEXT, Parameter2),
VT_UI8,
NULL,
0
},
{
KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_BASICSUPPORT,
AUDIOMODULE_PARAMETER_FLAG_CHANGE_NOTIFICATION,
(ULONG)RTL_FIELD_SIZE(AUDIOMODULE1_CONTEXT, Parameter3),
VT_UI4,
NULL,
0
},
};
inline
#pragma code_seg("PAGE")
NTSTATUS
AudioModule1_InitClass(
_In_ const AUDIOMODULE_DESCRIPTOR * Module,
_Inout_opt_ PVOID Context,
_In_ size_t Size,
_In_ KSAUDIOMODULE_NOTIFICATION * NotificationHeader,
_In_opt_ PPORTCLSNOTIFICATIONS PortNotifications
)
{
PAUDIOMODULE1_CONTEXT ctx = (PAUDIOMODULE1_CONTEXT)Context;
UNREFERENCED_PARAMETER(Module);
PAGED_CODE();
if (Context == NULL)
{
ASSERT(FALSE); // this should not happen.
return STATUS_INTERNAL_ERROR;
}
ASSERT(Size != 0);
RtlZeroMemory(Context, Size);
ctx->Notification.Header = *NotificationHeader;
ctx->PortNotifications = PortNotifications;
if (ctx->PortNotifications != NULL)
{
ctx->PortNotifications->AddRef();
}
return STATUS_SUCCESS;
}
inline
#pragma code_seg("PAGE")
NTSTATUS
AudioModule1_InitInstance(
_In_ const AUDIOMODULE_DESCRIPTOR * Module,
_In_opt_ PVOID TemplateContext,
_Inout_opt_ PVOID Context,
_In_ size_t Size,
_In_ ULONG InstanceId
)
{
PAUDIOMODULE1_CONTEXT ctx = (PAUDIOMODULE1_CONTEXT)Context;
UNREFERENCED_PARAMETER(Module);
PAGED_CODE();
if (Context == NULL)
{
ASSERT(FALSE); // this should not happen.
return STATUS_INTERNAL_ERROR;
}
ASSERT(TemplateContext != NULL);
ASSERT(Size != 0);
RtlCopyMemory(Context, TemplateContext, Size);
ctx->InstanceId = InstanceId;
ctx->Notification.Header.ProviderId.InstanceId = InstanceId;
if (ctx->PortNotifications != NULL)
{
ctx->PortNotifications->AddRef();
}
return STATUS_SUCCESS;
}
inline
#pragma code_seg("PAGE")
VOID
AudioModule1_Cleanup(
_In_ PVOID Context
)
{
PAUDIOMODULE1_CONTEXT ctx = (PAUDIOMODULE1_CONTEXT)Context;
PAGED_CODE();
if (Context == NULL)
{
ASSERT(FALSE); // this should not happen.
return;
}
SAFE_RELEASE(ctx->PortNotifications);
}
inline
#pragma code_seg("PAGE")
NTSTATUS
AudioModule1_Handler(
_Inout_opt_ PVOID Context,
_In_reads_bytes_(InBufferCb) PVOID InBuffer,
_In_ ULONG InBufferCb,
_Out_writes_bytes_opt_(*OutBufferCb) PVOID OutBuffer,
_Inout_ ULONG * OutBufferCb
)
{
NTSTATUS status = STATUS_SUCCESS;
BOOL fNewValue = FALSE;
PVOID currentValue;
PVOID inBuffer = NULL;
ULONG inBufferCb = 0;
PAUDIOMODULE1_CONTEXT ctx = (PAUDIOMODULE1_CONTEXT)Context;
AUDIOMODULE_PARAMETER_INFO * parameterInfo = NULL;
AUDIOMODULE1_CUSTOM_COMMAND * command = NULL;
PAGED_CODE();
if (ctx == NULL)
{
ASSERT(FALSE); // this should not happen.
status = STATUS_INTERNAL_ERROR;
goto exit;
}
//
// Basic parameter validation (module specific).
//
if (InBuffer == NULL || InBufferCb == 0)
{
return STATUS_INVALID_PARAMETER;
}
if (InBufferCb < sizeof(AUDIOMODULE1_CUSTOM_COMMAND))
{
return STATUS_INVALID_PARAMETER;
}
command = (AUDIOMODULE1_CUSTOM_COMMAND*)InBuffer;
//
// Validate the parameter referenced in the command.
//
switch (command->ParameterId)
{
case AudioModule1Parameter1:
currentValue = &ctx->Parameter1;
parameterInfo = &AudioModule1_ParameterInfo[AudioModule1Parameter1];
break;
case AudioModule1Parameter2:
currentValue = &ctx->Parameter2;
parameterInfo = &AudioModule1_ParameterInfo[AudioModule1Parameter2];
break;
case AudioModule1Parameter3:
currentValue = &ctx->Parameter3;
parameterInfo = &AudioModule1_ParameterInfo[AudioModule1Parameter3];
break;
default:
status = STATUS_INVALID_PARAMETER;
goto exit;
}
//
// Update input buffer ptr/size.
//
inBuffer = (PVOID)((ULONG_PTR)InBuffer + sizeof(AUDIOMODULE1_CUSTOM_COMMAND));
inBufferCb = InBufferCb - sizeof(AUDIOMODULE1_CUSTOM_COMMAND);
if (inBufferCb == 0)
{
inBuffer = NULL;
}
status = AudioModule_GenericHandler(
command->Verb,
command->ParameterId,
parameterInfo,
currentValue,
inBuffer,
inBufferCb,
OutBuffer,
OutBufferCb,
&fNewValue);
if (!NT_SUCCESS(status))
{
goto exit;
}
if (fNewValue && ctx->PortNotifications &&
(parameterInfo->Flags & AUDIOMODULE_PARAMETER_FLAG_CHANGE_NOTIFICATION))
{
// This logic assumes that access to this function is serialized.
ctx->Notification.CustomNotification.Type = AudioModule1ParameterChanged;
ctx->Notification.CustomNotification.ParameterChanged.ParameterId =
command->ParameterId;
AudioModule_SendNotification(ctx->PortNotifications,
(PVOID)&ctx->Notification,
(USHORT)sizeof(ctx->Notification));
}
// Normalize error code.
status = STATUS_SUCCESS;
exit:
return status;
}
#endif // _SYSVAD_AUDIOMODULE1_H_
|