xref: /reactos/sdk/include/psdk/ks.h (revision 5064f3c4)
1 /*
2     ReactOS
3     Kernel Streaming API
4 
5     by Andrew Greenwood
6 
7     NOTES:
8     This is a basic stubbing of the Kernel Streaming API header. It is
9     very incomplete - a lot of the #defines are not set to any value at all.
10 
11     Some of the structs/funcs may be incorrectly grouped.
12 
13     GUIDs need to be defined properly.
14 
15     AVStream functionality (XP and above, DirectX 8.0 and above) will NOT
16     implemented for a while.
17 
18     Some example code for interaction from usermode:
19     DeviceIoControl(
20         FilterHandle,
21         IOCTL_KS_PROPERTY,
22         &Property,
23         sizeof(KSPROPERTY),
24         &SeekingCapabilities,
25         sizeof(KS_SEEKING_CAPABILITIES),
26         &BytesReturned,
27         &Overlapped);
28 */
29 
30 #ifndef _KS_
31 #define _KS_
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef BUILDING_KS
38     #define KSDDKAPI
39 #else
40     #define KSDDKAPI //DECLSPEC_IMPORT /* TODO */
41 #endif
42 
43 
44 #define KSFILTER_NODE   ((ULONG)-1)
45 #define KSALL_NODES     ((ULONG)-1)
46 
47 #define KSSTRING_Filter L"{9B365890-165F-11D0-A195-0020AFD156E4}"
48 #define KSSTRING_Pin L"{146F1A80-4791-11D0-A5D6-28DB04C10000}"
49 #define KSSTRING_Clock L"{53172480-4791-11D0-A5D6-28DB04C10000}"
50 #define KSSTRING_Allocator L"{642F5D00-4791-11D0-A5D6-28DB04C10000}"
51 #define KSSTRING_AllocatorEx L"{091BB63B-603F-11D1-B067-00A0C9062802}"
52 #define KSSTRING_TopologyNode L"{0621061A-EE75-11D0-B915-00A0C9223196}"
53 
54 #define KSDATAFORMAT_BIT_ATTRIBUTES 1
55 #define KSDATAFORMAT_ATTRIBUTES (1 << KSDATAFORMAT_BIT_ATTRIBUTES)
56 
57 #if defined(_NTDDK_)
58 typedef PVOID PKSWORKER;
59 #endif
60 
61 #ifndef SIZEOF_ARRAY
62 #define SIZEOF_ARRAY(a) (sizeof(a)/sizeof((a)[0]))
63 #endif
64 
65 /* ===============================================================
66     GUID definition helpers
67 */
68 
69 #ifndef _NTRTL_
70 
71 #ifndef DEFINE_GUIDEX
72 #ifdef _MSC_VER
73 #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
74 #else
75 #define DEFINE_GUIDEX(name) EXTERN_C const GUID name
76 #endif
77 #endif /* !DEFINE_GUIDEX */
78 
79 #ifndef STATICGUIDOF
80 #define STATICGUIDOF(guid) STATIC_##guid
81 #endif
82 
83 #endif /* !_NTRTL_ */
84 
85 #if defined(__cplusplus)
86 
87 #if _MSC_VER >= 1100
88 #define DEFINE_GUIDSTRUCT(guid, name) struct __declspec(uuid(guid)) name
89 #define DEFINE_GUIDNAMED(name) __uuidof(struct name)
90 #else
91 #define DEFINE_GUIDSTRUCT(guid, name) \
92   extern const DECLSPEC_SELECTANY GUID __uuid__##name={STATIC_##name};
93 #define DEFINE_GUIDNAMED(name) __uuid__##name
94 #endif
95 
96 #else /* __cplusplus */
97 
98 #define DEFINE_GUIDSTRUCT(guid, name) DEFINE_GUIDEX(name)
99 #define DEFINE_GUIDNAMED(name) name
100 
101 #endif /* __cplusplus */
102 
103 #define STATIC_GUID_NULL \
104     0x00000000L, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
105 DEFINE_GUIDSTRUCT("00000000-0000-0000-0000-000000000000", GUID_NULL);
106 #define GUID_NULL DEFINE_GUIDNAMED(GUID_NULL)
107 
108 #define STATIC_KSNAME_Filter\
109     0x9b365890L, 0x165f, 0x11d0, {0xa1, 0x95, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}
110 DEFINE_GUIDSTRUCT("9b365890-165f-11d0-a195-0020afd156e4", KSNAME_Filter);
111 #define KSNAME_Filter DEFINE_GUIDNAMED(KSNAME_Filter)
112 
113 #define STATIC_KSMEMORY_TYPE_KERNEL_PAGED \
114     0xd833f8f8L, 0x7894, 0x11d1, {0xb0, 0x69, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02}
115 DEFINE_GUIDSTRUCT("d833f8f8-7894-11d1-b069-00a0c9062802", KSMEMORY_TYPE_KERNEL_PAGED);
116 #define KSMEMORY_TYPE_KERNEL_PAGED  DEFINE_GUIDNAMED(KSMEMORY_TYPE_KERNEL_PAGED)
117 
118 #define STATIC_KSDATAFORMAT_SUBTYPE_NONE \
119     0xe436eb8eL, 0x524f, 0x11ce, {0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}
120 DEFINE_GUIDSTRUCT("e436eb8e-524f-11ce-9f53-0020af0ba770", KSDATAFORMAT_SUBTYPE_NONE);
121 #define KSDATAFORMAT_SUBTYPE_NONE DEFINE_GUIDNAMED(KSDATAFORMAT_SUBTYPE_NONE)
122 
123 /* ===============================================================
124     I/O Control Codes
125 */
126 
127 #define IOCTL_KS_PROPERTY \
128     CTL_CODE(FILE_DEVICE_KS, 0x000, METHOD_NEITHER, FILE_ANY_ACCESS)
129 
130 #define IOCTL_KS_ENABLE_EVENT \
131     CTL_CODE(FILE_DEVICE_KS, 0x001, METHOD_NEITHER, FILE_ANY_ACCESS)
132 
133 #define IOCTL_KS_DISABLE_EVENT \
134     CTL_CODE(FILE_DEVICE_KS, 0x002, METHOD_NEITHER, FILE_ANY_ACCESS)
135 
136 #define IOCTL_KS_METHOD \
137     CTL_CODE(FILE_DEVICE_KS, 0x003, METHOD_NEITHER, FILE_ANY_ACCESS)
138 
139 #define IOCTL_KS_WRITE_STREAM \
140     CTL_CODE(FILE_DEVICE_KS, 0x004, METHOD_NEITHER, FILE_WRITE_ACCESS)
141 
142 #define IOCTL_KS_READ_STREAM \
143     CTL_CODE(FILE_DEVICE_KS, 0x005, METHOD_NEITHER, FILE_READ_ACCESS)
144 
145 #define IOCTL_KS_RESET_STATE \
146     CTL_CODE(FILE_DEVICE_KS, 0x006, METHOD_NEITHER, FILE_ANY_ACCESS)
147 
148 /* ===============================================================
149     Categories
150 */
151 
152 #define STATIC_KSCATEGORY_BRIDGE \
153     0x085AFF00L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
154 DEFINE_GUIDSTRUCT("085AFF00-62CE-11CF-A5D6-28DB04C10000", KSCATEGORY_BRIDGE);
155 #define KSCATEGORY_BRIDGE DEFINE_GUIDNAMED(KSCATEGORY_BRIDGE)
156 
157 #define STATIC_KSCATEGORY_CAPTURE \
158     0x65E8773DL, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
159 DEFINE_GUIDSTRUCT("65E8773D-8F56-11D0-A3B9-00A0C9223196", KSCATEGORY_CAPTURE);
160 #define KSCATEGORY_CAPTURE DEFINE_GUIDNAMED(KSCATEGORY_CAPTURE)
161 
162 #define STATIC_KSCATEGORY_RENDER \
163     0x65E8773EL, 0x8F56, 0x11D0, {0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
164 DEFINE_GUIDSTRUCT("65E8773E-8F56-11D0-A3B9-00A0C9223196", KSCATEGORY_RENDER);
165 #define KSCATEGORY_RENDER DEFINE_GUIDNAMED(KSCATEGORY_RENDER)
166 
167 #define STATIC_KSCATEGORY_MIXER \
168     0xAD809C00L, 0x7B88, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
169 DEFINE_GUIDSTRUCT("AD809C00-7B88-11D0-A5D6-28DB04C10000", KSCATEGORY_MIXER);
170 #define KSCATEGORY_MIXER DEFINE_GUIDNAMED(KSCATEGORY_MIXER)
171 
172 #define STATIC_KSCATEGORY_SPLITTER \
173     0x0A4252A0L, 0x7E70, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
174 DEFINE_GUIDSTRUCT("0A4252A0-7E70-11D0-A5D6-28DB04C10000", KSCATEGORY_SPLITTER);
175 #define KSCATEGORY_SPLITTER DEFINE_GUIDNAMED(KSCATEGORY_SPLITTER)
176 
177 #define STATIC_KSCATEGORY_DATACOMPRESSOR \
178     0x1E84C900L, 0x7E70, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
179 DEFINE_GUIDSTRUCT("1E84C900-7E70-11D0-A5D6-28DB04C10000", KSCATEGORY_DATACOMPRESSOR);
180 #define KSCATEGORY_DATACOMPRESSOR DEFINE_GUIDNAMED(KSCATEGORY_DATACOMPRESSOR)
181 
182 #define STATIC_KSCATEGORY_DATADECOMPRESSOR \
183     0x2721AE20L, 0x7E70, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
184 DEFINE_GUIDSTRUCT("2721AE20-7E70-11D0-A5D6-28DB04C10000", KSCATEGORY_DATADECOMPRESSOR);
185 #define KSCATEGORY_DATADECOMPRESSOR DEFINE_GUIDNAMED(KSCATEGORY_DATADECOMPRESSOR)
186 
187 #define STATIC_KSCATEGORY_DATATRANSFORM \
188     0x2EB07EA0L, 0x7E70, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
189 DEFINE_GUIDSTRUCT("2EB07EA0-7E70-11D0-A5D6-28DB04C10000", KSCATEGORY_DATATRANSFORM);
190 #define KSCATEGORY_DATATRANSFORM DEFINE_GUIDNAMED(KSCATEGORY_DATATRANSFORM)
191 
192 #define STATIC_KSCATEGORY_COMMUNICATIONSTRANSFORM \
193     0xCF1DDA2CL, 0x9743, 0x11D0, {0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
194 DEFINE_GUIDSTRUCT("CF1DDA2C-9743-11D0-A3EE-00A0C9223196", KSCATEGORY_COMMUNICATIONSTRANSFORM);
195 #define KSCATEGORY_COMMUNICATIONSTRANSFORM DEFINE_GUIDNAMED(KSCATEGORY_COMMUNICATIONSTRANSFORM)
196 
197 #define STATIC_KSCATEGORY_INTERFACETRANSFORM \
198     0xCF1DDA2DL, 0x9743, 0x11D0, {0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
199 DEFINE_GUIDSTRUCT("CF1DDA2D-9743-11D0-A3EE-00A0C9223196", KSCATEGORY_INTERFACETRANSFORM);
200 #define KSCATEGORY_INTERFACETRANSFORM DEFINE_GUIDNAMED(KSCATEGORY_INTERFACETRANSFORM)
201 
202 #define STATIC_KSCATEGORY_MEDIUMTRANSFORM \
203     0xCF1DDA2EL, 0x9743, 0x11D0, {0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
204 DEFINE_GUIDSTRUCT("CF1DDA2E-9743-11D0-A3EE-00A0C9223196", KSCATEGORY_MEDIUMTRANSFORM);
205 #define KSCATEGORY_MEDIUMTRANSFORM DEFINE_GUIDNAMED(KSCATEGORY_MEDIUMTRANSFORM)
206 
207 #define STATIC_KSCATEGORY_FILESYSTEM \
208     0x760FED5EL, 0x9357, 0x11D0, {0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
209 DEFINE_GUIDSTRUCT("760FED5E-9357-11D0-A3CC-00A0C9223196", KSCATEGORY_FILESYSTEM);
210 #define KSCATEGORY_FILESYSTEM DEFINE_GUIDNAMED(KSCATEGORY_FILESYSTEM)
211 
212 #define STATIC_KSCATEGORY_CLOCK \
213     0x53172480L, 0x4791, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
214 DEFINE_GUIDSTRUCT("53172480-4791-11D0-A5D6-28DB04C10000", KSCATEGORY_CLOCK);
215 #define KSCATEGORY_CLOCK DEFINE_GUIDNAMED(KSCATEGORY_CLOCK)
216 
217 #define STATIC_KSCATEGORY_PROXY \
218     0x97EBAACAL, 0x95BD, 0x11D0, {0xA3, 0xEA, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
219 DEFINE_GUIDSTRUCT("97EBAACA-95BD-11D0-A3EA-00A0C9223196", KSCATEGORY_PROXY);
220 #define KSCATEGORY_PROXY DEFINE_GUIDNAMED(KSCATEGORY_PROXY)
221 
222 #define STATIC_KSCATEGORY_QUALITY \
223     0x97EBAACBL, 0x95BD, 0x11D0, {0xA3, 0xEA, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
224 DEFINE_GUIDSTRUCT("97EBAACB-95BD-11D0-A3EA-00A0C9223196", KSCATEGORY_QUALITY);
225 #define KSCATEGORY_QUALITY DEFINE_GUIDNAMED(KSCATEGORY_QUALITY)
226 
227 /* ===============================================================
228     Common
229 */
230 
231 typedef struct {
232   GUID Set;
233   ULONG Id;
234   ULONG Flags;
235 } KSIDENTIFIER, *PKSIDENTIFIER;
236 
237 typedef KSIDENTIFIER KSPROPERTY, *PKSPROPERTY;
238 typedef KSIDENTIFIER KSMETHOD, *PKSMETHOD;
239 typedef KSIDENTIFIER KSEVENT, *PKSEVENT;
240 
241 typedef KSIDENTIFIER KSDEGRADE, *PKSDEGRADE;
242 
243 typedef KSIDENTIFIER KSPIN_INTERFACE, *PKSPIN_INTERFACE;
244 typedef KSIDENTIFIER KSPIN_MEDIUM, *PKSPIN_MEDIUM;
245 
246 typedef union {
247   struct {
248     ULONG FormatSize;
249     ULONG Flags;
250     ULONG SampleSize;
251     ULONG Reserved;
252     GUID MajorFormat;
253     GUID SubFormat;
254     GUID Specifier;
255   };
256   LONGLONG Alignment;
257 } KSDATAFORMAT, *PKSDATAFORMAT, KSDATARANGE, *PKSDATARANGE;
258 
259 typedef struct {
260   ULONG Size;
261   ULONG Flags;
262   GUID Attribute;
263 } KSATTRIBUTE, *PKSATTRIBUTE;
264 
265 
266 /* ===============================================================
267     Interface Sets - TODO
268 */
269 
270 #if 0
271 #define KSINTERFACESETID_Media
272 #define KSINTERFACE_STANDARD_STREAMING
273 #define KSINTERFACE_STANDARD_LOOPED_STREAMING
274 #define KSINTERFACE_STANDARD_CONTROL
275 #endif
276 
277 #define STATIC_KSINTERFACESETID_Standard \
278   0x1A8766A0L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
279 DEFINE_GUIDSTRUCT("1A8766A0-62CE-11CF-A5D6-28DB04C10000", KSINTERFACESETID_Standard);
280 #define KSINTERFACESETID_Standard DEFINE_GUIDNAMED(KSINTERFACESETID_Standard)
281 
282 typedef enum {
283   KSINTERFACE_STANDARD_STREAMING,
284   KSINTERFACE_STANDARD_LOOPED_STREAMING,
285   KSINTERFACE_STANDARD_CONTROL
286 } KSINTERFACE_STANDARD;
287 
288 #define STATIC_KSINTERFACESETID_FileIo \
289   0x8C6F932CL, 0xE771, 0x11D0, {0xB8, 0xFF, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
290 DEFINE_GUIDSTRUCT("8C6F932C-E771-11D0-B8FF-00A0C9223196", KSINTERFACESETID_FileIo);
291 #define KSINTERFACESETID_FileIo DEFINE_GUIDNAMED(KSINTERFACESETID_FileIo)
292 
293 /* ===============================================================
294     Mediums
295 */
296 
297 typedef enum {
298   KSINTERFACE_FILEIO_STREAMING
299 } KSINTERFACE_FILEIO;
300 
301 #define KSMEDIUM_TYPE_ANYINSTANCE       0
302 
303 #define STATIC_KSMEDIUMSETID_Standard \
304   0x4747B320L, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
305 DEFINE_GUIDSTRUCT("4747B320-62CE-11CF-A5D6-28DB04C10000", KSMEDIUMSETID_Standard);
306 #define KSMEDIUMSETID_Standard DEFINE_GUIDNAMED(KSMEDIUMSETID_Standard)
307 
308 /* ===============================================================
309     Clock Properties/Methods/Events
310 */
311 
312 #define STATIC_KSPROPSETID_Clock \
313   0xDF12A4C0L, 0xAC17, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
314 DEFINE_GUIDSTRUCT("DF12A4C0-AC17-11CF-A5D6-28DB04C10000", KSPROPSETID_Clock);
315 #define KSPROPSETID_Clock DEFINE_GUIDNAMED(KSPROPSETID_Clock)
316 
317 typedef enum {
318   KSPROPERTY_CLOCK_TIME,
319   KSPROPERTY_CLOCK_PHYSICALTIME,
320   KSPROPERTY_CLOCK_CORRELATEDTIME,
321   KSPROPERTY_CLOCK_CORRELATEDPHYSICALTIME,
322   KSPROPERTY_CLOCK_RESOLUTION,
323   KSPROPERTY_CLOCK_STATE,
324 #if defined(_NTDDK_)
325   KSPROPERTY_CLOCK_FUNCTIONTABLE
326 #endif // defined(_NTDDK_)
327 } KSPROPERTY_CLOCK;
328 
329 #define STATIC_KSEVENTSETID_Clock \
330   0x364D8E20L, 0x62C7, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
331 DEFINE_GUIDSTRUCT("364D8E20-62C7-11CF-A5D6-28DB04C10000", KSEVENTSETID_Clock);
332 #define KSEVENTSETID_Clock DEFINE_GUIDNAMED(KSEVENTSETID_Clock)
333 
334 typedef enum {
335   KSEVENT_CLOCK_INTERVAL_MARK,
336   KSEVENT_CLOCK_POSITION_MARK
337 } KSEVENT_CLOCK_POSITION;
338 
339 /* ===============================================================
340     Connection Properties/Methods/Events
341 */
342 
343 #define STATIC_KSPROPSETID_Connection \
344   0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
345 DEFINE_GUIDSTRUCT("1D58C920-AC9B-11CF-A5D6-28DB04C10000", KSPROPSETID_Connection);
346 #define KSPROPSETID_Connection DEFINE_GUIDNAMED(KSPROPSETID_Connection)
347 
348 typedef enum {
349   KSPROPERTY_CONNECTION_STATE,
350   KSPROPERTY_CONNECTION_PRIORITY,
351   KSPROPERTY_CONNECTION_DATAFORMAT,
352   KSPROPERTY_CONNECTION_ALLOCATORFRAMING,
353   KSPROPERTY_CONNECTION_PROPOSEDATAFORMAT,
354   KSPROPERTY_CONNECTION_ACQUIREORDERING,
355   KSPROPERTY_CONNECTION_ALLOCATORFRAMING_EX,
356   KSPROPERTY_CONNECTION_STARTAT
357 } KSPROPERTY_CONNECTION;
358 
359 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_STATE(GetHandler, SetHandler)\
360     DEFINE_KSPROPERTY_ITEM(\
361         KSPROPERTY_CONNECTION_STATE,\
362         (GetHandler),\
363         sizeof(KSPROPERTY),\
364         sizeof(KSSTATE),\
365         (SetHandler),\
366         NULL, 0, NULL, NULL, 0)
367 
368 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_PRIORITY(GetHandler, SetHandler)\
369     DEFINE_KSPROPERTY_ITEM(\
370         KSPROPERTY_CONNECTION_PRIORITY,\
371         (GetHandler),\
372         sizeof(KSPROPERTY),\
373         sizeof(KSPRIORITY),\
374         (SetHandler),\
375         NULL, 0, NULL, NULL, 0)
376 
377 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_DATAFORMAT(GetHandler, SetHandler)\
378     DEFINE_KSPROPERTY_ITEM(\
379         KSPROPERTY_CONNECTION_DATAFORMAT,\
380         (GetHandler),\
381         sizeof(KSPROPERTY),\
382         0,\
383         (SetHandler),\
384         NULL, 0, NULL, NULL, 0)
385 
386 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_ALLOCATORFRAMING(Handler)\
387     DEFINE_KSPROPERTY_ITEM(\
388         KSPROPERTY_CONNECTION_ALLOCATORFRAMING,\
389         (Handler),\
390         sizeof(KSPROPERTY),\
391         sizeof(KSALLOCATOR_FRAMING),\
392         NULL, NULL, 0, NULL, NULL, 0)
393 
394 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_ALLOCATORFRAMING_EX(Handler)\
395     DEFINE_KSPROPERTY_ITEM(\
396         KSPROPERTY_CONNECTION_ALLOCATORFRAMING_EX,\
397         (Handler),\
398         sizeof(KSPROPERTY),\
399         0,\
400         NULL, NULL, 0, NULL, NULL, 0)
401 
402 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_PROPOSEDATAFORMAT(Handler)\
403     DEFINE_KSPROPERTY_ITEM(\
404         KSPROPERTY_CONNECTION_PROPOSEDATAFORMAT,\
405         NULL,\
406         sizeof(KSPROPERTY),\
407         sizeof(KSDATAFORMAT),\
408         (Handler),\
409         NULL, 0, NULL, NULL, 0)
410 
411 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_ACQUIREORDERING(Handler)\
412     DEFINE_KSPROPERTY_ITEM(\
413         KSPROPERTY_CONNECTION_ACQUIREORDERING,\
414         (Handler),\
415         sizeof(KSPROPERTY),\
416         sizeof(int),\
417         NULL, NULL, 0, NULL, NULL, 0)
418 
419 #define DEFINE_KSPROPERTY_ITEM_CONNECTION_STARTAT(Handler)\
420     DEFINE_KSPROPERTY_ITEM(\
421         KSPROPERTY_CONNECTION_STARTAT,\
422         NULL,\
423         sizeof(KSPROPERTY),\
424         sizeof(KSRELATIVEEVENT),\
425         (Handler),\
426         NULL, 0, NULL, NULL, 0)
427 
428 typedef enum {
429   KSEVENT_CONNECTION_POSITIONUPDATE,
430   KSEVENT_CONNECTION_DATADISCONTINUITY,
431   KSEVENT_CONNECTION_TIMEDISCONTINUITY,
432   KSEVENT_CONNECTION_PRIORITY,
433   KSEVENT_CONNECTION_ENDOFSTREAM
434 } KSEVENT_CONNECTION;
435 
436 /* ===============================================================
437     General
438     Properties/Methods/Events
439 */
440 
441 #define STATIC_KSPROPSETID_General\
442   0x1464EDA5L, 0x6A8F, 0x11D1, {0x9A, 0xA7, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
443 DEFINE_GUIDSTRUCT("1464EDA5-6A8F-11D1-9AA7-00A0C9223196", KSPROPSETID_General);
444 #define KSPROPSETID_General DEFINE_GUIDNAMED(KSPROPSETID_General)
445 
446 typedef enum {
447   KSPROPERTY_GENERAL_COMPONENTID
448 } KSPROPERTY_GENERAL;
449 
450 /* ===============================================================
451     Graph Manager
452     Properties/Methods/Events
453 */
454 
455 #define KSPROPSETID_GM \
456   0xAF627536L, 0xE719, 0x11D2, {0x8A, 0x1D, 0x00, 0x60, 0x97, 0xD2, 0xDF, 0x5D}
457 
458 typedef enum {
459   KSPROPERTY_GM_GRAPHMANAGER,
460   KSPROPERTY_GM_TIMESTAMP_CLOCK,
461   KSPROPERTY_GM_RATEMATCH,
462   KSPROPERTY_GM_RENDERCLOCK
463 } KSPROPERTY_GM;
464 
465 /* ===============================================================
466     Media Seeking
467     Properties/Methods/Events
468 */
469 
470 #define STATIC_KSPROPSETID_MediaSeeking\
471   0xEE904F0CL, 0xD09B, 0x11D0, {0xAB, 0xE9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
472 DEFINE_GUIDSTRUCT("EE904F0C-D09B-11D0-ABE9-00A0C9223196", KSPROPSETID_MediaSeeking);
473 #define KSPROPSETID_MediaSeeking DEFINE_GUIDNAMED(KSPROPSETID_MediaSeeking)
474 
475 typedef enum {
476   KSPROPERTY_MEDIASEEKING_CAPABILITIES,
477   KSPROPERTY_MEDIASEEKING_FORMATS,
478   KSPROPERTY_MEDIASEEKING_TIMEFORMAT,
479   KSPROPERTY_MEDIASEEKING_POSITION,
480   KSPROPERTY_MEDIASEEKING_STOPPOSITION,
481   KSPROPERTY_MEDIASEEKING_POSITIONS,
482   KSPROPERTY_MEDIASEEKING_DURATION,
483   KSPROPERTY_MEDIASEEKING_AVAILABLE,
484   KSPROPERTY_MEDIASEEKING_PREROLL,
485   KSPROPERTY_MEDIASEEKING_CONVERTTIMEFORMAT
486 } KSPROPERTY_MEDIASEEKING;
487 
488 typedef enum {
489   KS_SEEKING_NoPositioning,
490   KS_SEEKING_AbsolutePositioning,
491   KS_SEEKING_RelativePositioning,
492   KS_SEEKING_IncrementalPositioning,
493   KS_SEEKING_PositioningBitsMask = 0x3,
494   KS_SEEKING_SeekToKeyFrame,
495   KS_SEEKING_ReturnTime = 0x8
496 } KS_SEEKING_FLAGS;
497 
498 typedef enum {
499   KS_SEEKING_CanSeekAbsolute = 0x1,
500   KS_SEEKING_CanSeekForwards = 0x2,
501   KS_SEEKING_CanSeekBackwards = 0x4,
502   KS_SEEKING_CanGetCurrentPos = 0x8,
503   KS_SEEKING_CanGetStopPos = 0x10,
504   KS_SEEKING_CanGetDuration = 0x20,
505   KS_SEEKING_CanPlayBackwards = 0x40
506 } KS_SEEKING_CAPABILITIES;
507 
508 typedef struct {
509   LONGLONG Current;
510   LONGLONG Stop;
511   KS_SEEKING_FLAGS CurrentFlags;
512   KS_SEEKING_FLAGS StopFlags;
513 } KSPROPERTY_POSITIONS, *PKSPROPERTY_POSITIONS;
514 
515 typedef struct {
516   LONGLONG Earliest;
517   LONGLONG Latest;
518 } KSPROPERTY_MEDIAAVAILABLE, *PKSPROPERTY_MEDIAAVAILABLE;
519 
520 typedef struct {
521   KSPROPERTY Property;
522   GUID SourceFormat;
523   GUID TargetFormat;
524   LONGLONG Time;
525 } KSP_TIMEFORMAT, *PKSP_TIMEFORMAT;
526 
527 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_CAPABILITIES(Handler)\
528     DEFINE_KSPROPERTY_ITEM(\
529         KSPROPERTY_MEDIASEEKING_CAPABILITIES,\
530         (Handler),\
531         sizeof(KSPROPERTY),\
532         sizeof(KS_SEEKING_CAPABILITIES),\
533         NULL, NULL, 0, NULL, NULL, 0)
534 
535 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_FORMATS(Handler)\
536     DEFINE_KSPROPERTY_ITEM(\
537         KSPROPERTY_MEDIASEEKING_FORMATS,\
538         (Handler),\
539         sizeof(KSPROPERTY),\
540         0,\
541         NULL, NULL, 0, NULL, NULL, 0)
542 
543 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_TIMEFORMAT(GetHandler, SetHandler)\
544     DEFINE_KSPROPERTY_ITEM(\
545         KSPROPERTY_MEDIASEEKING_TIMEFORMAT,\
546         (GetHandler),\
547         sizeof(KSPROPERTY),\
548         sizeof(GUID),\
549         (SetHandler),\
550         NULL, 0, NULL, NULL, 0)
551 
552 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_POSITION(Handler)\
553     DEFINE_KSPROPERTY_ITEM(\
554         KSPROPERTY_MEDIASEEKING_POSITION,\
555         (Handler),\
556         sizeof(KSPROPERTY),\
557         sizeof(LONGLONG),\
558         NULL, NULL, 0, NULL, NULL, 0)
559 
560 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_STOPPOSITION(Handler)\
561     DEFINE_KSPROPERTY_ITEM(\
562         KSPROPERTY_MEDIASEEKING_STOPPOSITION,\
563         (Handler),\
564         sizeof(KSPROPERTY),\
565         sizeof(LONGLONG),\
566         NULL, NULL, 0, NULL, NULL, 0)
567 
568 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_POSITIONS(Handler)\
569     DEFINE_KSPROPERTY_ITEM(\
570         KSPROPERTY_MEDIASEEKING_POSITIONS,\
571         NULL,\
572         sizeof(KSPROPERTY),\
573         sizeof(KSPROPERTY_POSITIONS),\
574         (Handler),\
575         NULL, 0, NULL, NULL, 0)
576 
577 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_DURATION(Handler)\
578     DEFINE_KSPROPERTY_ITEM(\
579         KSPROPERTY_MEDIASEEKING_DURATION,\
580         (Handler),\
581         sizeof(KSPROPERTY),\
582         sizeof(LONGLONG),\
583         NULL, NULL, 0, NULL, NULL, 0)
584 
585 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_AVAILABLE(Handler)\
586     DEFINE_KSPROPERTY_ITEM(\
587         KSPROPERTY_MEDIASEEKING_AVAILABLE,\
588         (Handler),\
589         sizeof(KSPROPERTY),\
590         sizeof(KSPROPERTY_MEDIAAVAILABLE),\
591         NULL, NULL, 0, NULL, NULL, 0)
592 
593 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_PREROLL(Handler)\
594     DEFINE_KSPROPERTY_ITEM(\
595         KSPROPERTY_MEDIASEEKING_PREROLL,\
596         (Handler),\
597         sizeof(KSPROPERTY),\
598         sizeof(LONGLONG),\
599         NULL, NULL, 0, NULL, NULL, 0)
600 
601 #define DEFINE_KSPROPERTY_ITEM_MEDIASEEKING_CONVERTTIMEFORMAT(Handler)\
602     DEFINE_KSPROPERTY_ITEM(\
603         KSPROPERTY_MEDIASEEKING_CONVERTTIMEFORMAT,\
604         (Handler),\
605         sizeof(KSP_TIMEFORMAT),\
606         sizeof(LONGLONG),\
607         NULL, NULL, 0, NULL, NULL, 0)
608 
609 /* ===============================================================
610     Pin
611     Properties/Methods/Events
612 */
613 
614 #define STATIC_KSPROPSETID_Pin\
615   0x8C134960L, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}
616 DEFINE_GUIDSTRUCT("8C134960-51AD-11CF-878A-94F801C10000", KSPROPSETID_Pin);
617 #define KSPROPSETID_Pin DEFINE_GUIDNAMED(KSPROPSETID_Pin)
618 
619 #define STATIC_KSNAME_Pin\
620   0x146F1A80L, 0x4791, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
621 DEFINE_GUIDSTRUCT("146F1A80-4791-11D0-A5D6-28DB04C10000", KSNAME_Pin);
622 #define KSNAME_Pin DEFINE_GUIDNAMED(KSNAME_Pin)
623 
624 typedef enum {
625   KSPROPERTY_PIN_CINSTANCES,
626   KSPROPERTY_PIN_CTYPES,
627   KSPROPERTY_PIN_DATAFLOW,
628   KSPROPERTY_PIN_DATARANGES,
629   KSPROPERTY_PIN_DATAINTERSECTION,
630   KSPROPERTY_PIN_INTERFACES,
631   KSPROPERTY_PIN_MEDIUMS,
632   KSPROPERTY_PIN_COMMUNICATION,
633   KSPROPERTY_PIN_GLOBALCINSTANCES,
634   KSPROPERTY_PIN_NECESSARYINSTANCES,
635   KSPROPERTY_PIN_PHYSICALCONNECTION,
636   KSPROPERTY_PIN_CATEGORY,
637   KSPROPERTY_PIN_NAME,
638   KSPROPERTY_PIN_CONSTRAINEDDATARANGES,
639   KSPROPERTY_PIN_PROPOSEDATAFORMAT
640 } KSPROPERTY_PIN;
641 
642 typedef struct {
643   KSPROPERTY Property;
644   ULONG PinId;
645   ULONG Reserved;
646 } KSP_PIN, *PKSP_PIN;
647 
648 #define KSINSTANCE_INDETERMINATE ((ULONG)-1)
649 
650 typedef struct {
651   ULONG PossibleCount;
652   ULONG CurrentCount;
653 } KSPIN_CINSTANCES, *PKSPIN_CINSTANCES;
654 
655 typedef struct {
656   ULONG Size;
657   ULONG Pin;
658   WCHAR SymbolicLinkName[1];
659 } KSPIN_PHYSICALCONNECTION, *PKSPIN_PHYSICALCONNECTION;
660 
661 /* ===============================================================
662     Quality
663     Properties/Methods/Events
664 */
665 
666 #define KSPROPSETID_Quality \
667   0xD16AD380L, 0xAC1A, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
668 
669 typedef enum {
670   KSPROPERTY_QUALITY_REPORT,
671   KSPROPERTY_QUALITY_ERROR
672 } KSPROPERTY_QUALITY;
673 
674 /* ===============================================================
675     Stream
676     Properties/Methods/Events
677 */
678 
679 #define STATIC_KSPROPSETID_Stream\
680   0x65aaba60L, 0x98ae, 0x11cf, {0xa1, 0x0d, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}
681 DEFINE_GUIDSTRUCT("65aaba60-98ae-11cf-a10d-0020afd156e4", KSPROPSETID_Stream);
682 #define KSPROPSETID_Stream DEFINE_GUIDNAMED(KSPROPSETID_Stream)
683 
684 typedef enum {
685   KSPROPERTY_STREAM_ALLOCATOR,
686   KSPROPERTY_STREAM_QUALITY,
687   KSPROPERTY_STREAM_DEGRADATION,
688   KSPROPERTY_STREAM_MASTERCLOCK,
689   KSPROPERTY_STREAM_TIMEFORMAT,
690   KSPROPERTY_STREAM_PRESENTATIONTIME,
691   KSPROPERTY_STREAM_PRESENTATIONEXTENT,
692   KSPROPERTY_STREAM_FRAMETIME,
693   KSPROPERTY_STREAM_RATECAPABILITY,
694   KSPROPERTY_STREAM_RATE,
695   KSPROPERTY_STREAM_PIPE_ID
696 } KSPROPERTY_STREAM;
697 
698 #define DEFINE_KSPROPERTY_ITEM_STREAM_ALLOCATOR(GetHandler, SetHandler)\
699     DEFINE_KSPROPERTY_ITEM(\
700         KSPROPERTY_STREAM_ALLOCATOR,\
701         (GetHandler),\
702         sizeof(KSPROPERTY),\
703         sizeof(HANDLE),\
704         (SetHandler),\
705         NULL, 0, NULL, NULL, 0)
706 
707 #define DEFINE_KSPROPERTY_ITEM_STREAM_QUALITY(Handler)\
708     DEFINE_KSPROPERTY_ITEM(\
709         KSPROPERTY_STREAM_QUALITY,\
710         (Handler),\
711         sizeof(KSPROPERTY),\
712         sizeof(KSQUALITY_MANAGER),\
713         NULL, NULL, 0, NULL, NULL, 0)
714 
715 #define DEFINE_KSPROPERTY_ITEM_STREAM_DEGRADATION(GetHandler, SetHandler)\
716     DEFINE_KSPROPERTY_ITEM(\
717         KSPROPERTY_STREAM_DEGRADATION,\
718         (GetHandler),\
719         sizeof(KSPROPERTY),\
720         0,\
721         (SetHandler),\
722         NULL, 0, NULL, NULL, 0)
723 
724 #define DEFINE_KSPROPERTY_ITEM_STREAM_MASTERCLOCK(GetHandler, SetHandler)\
725     DEFINE_KSPROPERTY_ITEM(\
726         KSPROPERTY_STREAM_MASTERCLOCK,\
727         (GetHandler),\
728         sizeof(KSPROPERTY),\
729         sizeof(HANDLE),\
730         (SetHandler),\
731         NULL, 0, NULL, NULL, 0)
732 
733 #define DEFINE_KSPROPERTY_ITEM_STREAM_TIMEFORMAT(Handler)\
734     DEFINE_KSPROPERTY_ITEM(\
735         KSPROPERTY_STREAM_TIMEFORMAT,\
736         (Handler),\
737         sizeof(KSPROPERTY),\
738         sizeof(GUID),\
739         NULL, NULL, 0, NULL, NULL, 0)
740 
741 #define DEFINE_KSPROPERTY_ITEM_STREAM_PRESENTATIONTIME(GetHandler, SetHandler)\
742     DEFINE_KSPROPERTY_ITEM(\
743         KSPROPERTY_STREAM_PRESENTATIONTIME,\
744         (GetHandler),\
745         sizeof(KSPROPERTY),\
746         sizeof(KSTIME),\
747         (SetHandler),\
748         NULL, 0, NULL, NULL, 0)
749 
750 #define DEFINE_KSPROPERTY_ITEM_STREAM_PRESENTATIONEXTENT(Handler)\
751     DEFINE_KSPROPERTY_ITEM(\
752         KSPROPERTY_STREAM_PRESENTATIONEXTENT,\
753         (Handler),\
754         sizeof(KSPROPERTY),\
755         sizeof(LONGLONG),\
756         NULL, NULL, 0, NULL, NULL, 0)
757 
758 #define DEFINE_KSPROPERTY_ITEM_STREAM_FRAMETIME(Handler)\
759     DEFINE_KSPROPERTY_ITEM(\
760         KSPROPERTY_STREAM_FRAMETIME,\
761         (Handler),\
762         sizeof(KSPROPERTY),\
763         sizeof(KSFRAMETIME),\
764         NULL, NULL, 0, NULL, NULL, 0)
765 
766 #define DEFINE_KSPROPERTY_ITEM_STREAM_RATECAPABILITY(Handler)\
767     DEFINE_KSPROPERTY_ITEM(\
768         KSPROPERTY_STREAM_RATECAPABILITY,\
769         (Handler),\
770         sizeof(KSRATE_CAPABILITY),\
771         sizeof(KSRATE),\
772         NULL, NULL, 0, NULL, NULL, 0)
773 
774 #define DEFINE_KSPROPERTY_ITEM_STREAM_RATE(GetHandler, SetHandler)\
775     DEFINE_KSPROPERTY_ITEM(\
776         KSPROPERTY_STREAM_RATE,\
777         (GetHandler),\
778         sizeof(KSPROPERTY),\
779         sizeof(KSRATE),\
780         (SetHandler),\
781         NULL, 0, NULL, NULL, 0)
782 
783 #define DEFINE_KSPROPERTY_ITEM_STREAM_PIPE_ID(GetHandler, SetHandler)\
784     DEFINE_KSPROPERTY_ITEM(\
785         KSPROPERTY_STREAM_PIPE_ID,\
786         (GetHandler),\
787         sizeof(KSPROPERTY),\
788         sizeof(HANDLE),\
789         (SetHandler),\
790         NULL, 0, NULL, NULL, 0)
791 
792 /* ===============================================================
793     StreamAllocator
794     Properties/Methods/Events
795 */
796 
797 #define STATIC_KSPROPSETID_StreamAllocator\
798   0xcf6e4342L, 0xec87, 0x11cf, {0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}
799 DEFINE_GUIDSTRUCT("cf6e4342-ec87-11cf-a130-0020afd156e4", KSPROPSETID_StreamAllocator);
800 #define KSPROPSETID_StreamAllocator DEFINE_GUIDNAMED(KSPROPSETID_StreamAllocator)
801 
802 typedef enum {
803   KSPROPERTY_STREAMALLOCATOR_FUNCTIONTABLE,
804   KSPROPERTY_STREAMALLOCATOR_STATUS
805 } KSPROPERTY_STREAMALLOCATOR;
806 
807 #define KSMETHODSETID_StreamAllocator \
808   0xcf6e4341L, 0xec87, 0x11cf, {0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4}
809 
810 typedef enum {
811   KSMETHOD_STREAMALLOCATOR_ALLOC,
812   KSMETHOD_STREAMALLOCATOR_FREE
813 } KSMETHOD_STREAMALLOCATOR;
814 
815 #define KSEVENTSETID_StreamAllocator
816 
817 typedef enum {
818   KSEVENT_STREAMALLOCATOR_INTERNAL_FREEFRAME,
819   KSEVENT_STREAMALLOCATOR_FREEFRAME
820 } KSEVENT_STREAMALLOCATOR;
821 
822 /* ===============================================================
823     StreamInterface
824     Properties/Methods/Events
825 */
826 
827 #define KSPROPSETID_StreamInterface \
828   0x1fdd8ee1L, 0x9cd3, 0x11d0, 0x82, 0xaa, 0x00, 0x00, 0xf8, 0x22, 0xfe, 0x8a
829 
830 typedef enum {
831   KSPROPERTY_STREAMINTERFACE_HEADERSIZE
832 } KSPROPERTY_STREAMINTERFACE;
833 
834 /* ===============================================================
835     Topology
836     Properties/Methods/Events
837 */
838 
839 #define STATIC_KSPROPSETID_Topology\
840   0x720D4AC0L, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
841 DEFINE_GUIDSTRUCT("720D4AC0-7533-11D0-A5D6-28DB04C10000", KSPROPSETID_Topology);
842 #define KSPROPSETID_Topology DEFINE_GUIDNAMED(KSPROPSETID_Topology)
843 
844 typedef enum {
845   KSPROPERTY_TOPOLOGY_CATEGORIES,
846   KSPROPERTY_TOPOLOGY_NODES,
847   KSPROPERTY_TOPOLOGY_CONNECTIONS,
848   KSPROPERTY_TOPOLOGY_NAME
849 } KSPROPERTY_TOPOLOGY;
850 
851 /* ===============================================================
852     Property Sets for audio drivers - TODO
853 */
854 
855 #define STATIC_KSPROPTYPESETID_General \
856   0x97E99BA0L, 0xBDEA, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}
857 DEFINE_GUIDSTRUCT("97E99BA0-BDEA-11CF-A5D6-28DB04C10000", KSPROPTYPESETID_General);
858 #define KSPROPTYPESETID_General DEFINE_GUIDNAMED(KSPROPTYPESETID_General)
859 
860 /*
861     KSPROPERTY_AC3_ALTERNATE_AUDIO
862     KSPROPERTY_AC3_BIT_STREAM_MODE
863     KSPROPERTY_AC3_DIALOGUE_LEVEL
864     KSPROPERTY_AC3_DOWNMIX
865     KSPROPERTY_AC3_ERROR_CONCEALMENT
866     KSPROPERTY_AC3_LANGUAGE_CODE
867     KSPROPERTY_AC3_ROOM_TYPE
868 */
869 
870 #define KSPROPSETID_Acoustic_Echo_Cancel
871 /*
872     KSPROPERTY_AEC_MODE
873     KSPROPERTY_AEC_NOISE_FILL_ENABLE
874     KSPROPERTY_AEC_STATUS
875 */
876 
877 /*
878     KSPROPERTY_AUDIO_3D_INTERFACE
879     KSPROPERTY_AUDIO_AGC
880     KSPROPERTY_AUDIO_ALGORITHM_INSTANCE
881     KSPROPERTY_AUDIO_BASS
882     KSPROPERTY_AUDIO_BASS_BOOST
883     KSPROPERTY_AUDIO_CHANNEL_CONFIG
884     KSPROPERTY_AUDIO_CHORUS_LEVEL
885     KSPROPERTY_AUDIO_COPY_PROTECTION
886     KSPROPERTY_AUDIO_CPU_RESOURCES
887     KSPROPERTY_AUDIO_DELAY
888     KSPROPERTY_AUDIO_DEMUX_DEST
889     KSPROPERTY_AUDIO_DEV_SPECIFIC
890     KSPROPERTY_AUDIO_DYNAMIC_RANGE
891     KSPROPERTY_AUDIO_DYNAMIC_SAMPLING_RATE
892     KSPROPERTY_AUDIO_EQ_BANDS
893     KSPROPERTY_AUDIO_EQ_LEVEL
894     KSPROPERTY_AUDIO_FILTER_STATE
895     KSPROPERTY_AUDIO_LATENCY
896     KSPROPERTY_AUDIO_LOUDNESS
897     KSPROPERTY_AUDIO_MANUFACTURE_GUID
898     KSPROPERTY_AUDIO_MID
899     KSPROPERTY_AUDIO_MIX_LEVEL_CAPS
900     KSPROPERTY_AUDIO_MIX_LEVEL_TABLE
901     KSPROPERTY_AUDIO_MUTE
902     KSPROPERTY_AUDIO_MUX_SOURCE
903     KSPROPERTY_AUDIO_NUM_EQ_BANDS
904     KSPROPERTY_AUDIO_PEAKMETER
905     KSPROPERTY_AUDIO_POSITION
906     KSPROPERTY_AUDIO_PREFERRED_STATUS
907     KSPROPERTY_AUDIO_PRODUCT_GUID
908     KSPROPERTY_AUDIO_QUALITY
909     KSPROPERTY_AUDIO_REVERB_LEVEL
910     KSPROPERTY_AUDIO_SAMPLING_RATE
911     KSPROPERTY_AUDIO_STEREO_ENHANCE
912     KSPROPERTY_AUDIO_STEREO_SPEAKER_GEOMETRY
913     KSPROPERTY_AUDIO_SURROUND_ENCODE
914     KSPROPERTY_AUDIO_TREBLE
915     KSPROPERTY_AUDIO_VOLUMELEVEL
916     KSPROPERTY_AUDIO_WIDE_MODE
917     KSPROPERTY_AUDIO_WIDENESS
918 */
919 
920 #define KSPROPSETID_AudioGfx
921 /*
922     KSPROPERTY_AUDIOGFX_CAPTURETARGETDEVICEID
923     KSPROPERTY_AUDIOGFX_RENDERTARGETDEVICEID
924 */
925 
926 #define KSPROPSETID_DirectSound3DBuffer
927 /*
928     KSPROPERTY_DIRECTSOUND3DBUFFER_ALL
929     KSPROPERTY_DIRECTSOUND3DBUFFER_CONEANGLES
930     KSPROPERTY_DIRECTSOUND3DBUFFER_CONEORIENTATION
931     KSPROPERTY_DIRECTSOUND3DBUFFER_CONEOUTSIDEVOLUME
932     KSPROPERTY_DIRECTSOUND3DBUFFER_MAXDISTANCE
933     KSPROPERTY_DIRECTSOUND3DBUFFER_MINDISTANCE
934     KSPROPERTY_DIRECTSOUND3DBUFFER_MODE
935     KSPROPERTY_DIRECTSOUND3DBUFFER_POSITION
936     KSPROPERTY_DIRECTSOUND3DBUFFER_VELOCITY
937 */
938 
939 #define KSPROPSETID_DirectSound3DListener
940 /*
941     KSPROPERTY_DIRECTSOUND3DLISTENER_ALL
942     KSPROPERTY_DIRECTSOUND3DLISTENER_ALLOCATION
943     KSPROPERTY_DIRECTSOUND3DLISTENER_BATCH
944     KSPROPERTY_DIRECTSOUND3DLISTENER_DISTANCEFACTOR
945     KSPROPERTY_DIRECTSOUND3DLISTENER_DOPPLERFACTOR
946     KSPROPERTY_DIRECTSOUND3DLISTENER_ORIENTATION
947     KSPROPERTY_DIRECTSOUND3DLISTENER_POSITION
948     KSPROPERTY_DIRECTSOUND3DLISTENER_ROLLOFFFACTOR
949     KSPROPERTY_DIRECTSOUND3DLISTENER_VELOCITY
950 */
951 
952 #define KSPROPSETID_Hrtf3d
953 /*
954     KSPROPERTY_HRTF3D_FILTER_FORMAT
955     KSPROPERTY_HRTF3D_INITIALIZE
956     KSPROPERTY_HRTF3D_PARAMS
957 */
958 
959 #define KSPROPSETID_Itd3d
960 /*
961     KSPROPERTY_ITD3D_PARAMS
962 */
963 
964 #define KSPROPSETID_TopologyNode
965 /*
966     KSPROPERTY_TOPOLOGYNODE_ENABLE
967     KSPROPERTY_TOPOLOGYNODE_RESET
968 */
969 
970 
971 /* ===============================================================
972     Node Types
973 */
974 /*
975     KSNODETYPE_3D_EFFECTS
976     KSNODETYPE_ACOUSTIC_ECHO_CANCEL
977     KSNODETYPE_ADC
978     KSNODETYPE_AGC
979     KSNODETYPE_CHORUS
980     KSNODETYPE_DAC
981     KSNODETYPE_DELAY
982     KSNODETYPE_DEMUX
983     KSNODETYPE_DEV_SPECIFIC
984     KSNODETYPE_DMSYNTH
985     KSNODETYPE_DMSYNTH_CAPS
986     KSNODETYPE_DRM_DESCRAMBLE
987     KSNODETYPE_EQUALIZER
988     KSNODETYPE_LOUDNESS
989     KSNODETYPE_MUTE
990     KSNODETYPE_MUX
991     KSNODETYPE_PEAKMETER
992     KSNODETYPE_PROLOGIC_DECODER
993     KSNODETYPE_PROLOGIC_ENCODER
994     KSNODETYPE_REVERB
995     KSNODETYPE_SRC
996     KSNODETYPE_STEREO_ENHANCE
997     KSNODETYPE_STEREO_WIDE
998     KSNODETYPE_SUM
999     KSNODETYPE_SUPERMIX
1000     KSNODETYPE_SWMIDI
1001     KSNODETYPE_SWSYNTH
1002     KSNODETYPE_SYNTHESIZER
1003     KSNODETYPE_TONE
1004     KSNODETYPE_VOLUME
1005 */
1006 
1007 typedef PVOID KSDEVICE_HEADER, KSOBJECT_HEADER, KSOBJECT_BAG;
1008 
1009 /* ===============================================================
1010     Method Types
1011 */
1012 
1013 #define KSMETHOD_TYPE_NONE         0x00000000
1014 #define KSMETHOD_TYPE_READ         0x00000001
1015 #define KSMETHOD_TYPE_WRITE        0x00000002
1016 #define KSMETHOD_TYPE_MODIFY       0x00000003
1017 #define KSMETHOD_TYPE_SOURCE       0x00000004
1018 #define KSMETHOD_TYPE_SEND         0x00000001
1019 #define KSMETHOD_TYPE_SETSUPPORT   0x00000100
1020 #define KSMETHOD_TYPE_BASICSUPPORT 0x00000200
1021 
1022 /* ===============================================================
1023     Property Types
1024 */
1025 
1026 #define KSPROPERTY_TYPE_GET            0x00000001
1027 #define KSPROPERTY_TYPE_SET            0x00000002
1028 #define KSPROPERTY_TYPE_SETSUPPORT     0x00000100
1029 #define KSPROPERTY_TYPE_BASICSUPPORT   0x00000200
1030 #define KSPROPERTY_TYPE_RELATIONS      0x00000400
1031 #define KSPROPERTY_TYPE_SERIALIZESET   0x00000800
1032 #define KSPROPERTY_TYPE_UNSERIALIZESET 0x00001000
1033 #define KSPROPERTY_TYPE_SERIALIZERAW   0x00002000
1034 #define KSPROPERTY_TYPE_UNSERIALIZERAW 0x00004000
1035 #define KSPROPERTY_TYPE_SERIALIZESIZE  0x00008000
1036 #define KSPROPERTY_TYPE_DEFAULT_VALUES 0x00010000
1037 
1038 /* ===============================================================
1039     Topology Methods/Properties
1040 */
1041 
1042 #define KSMETHOD_TYPE_TOPOLOGY         0x10000000
1043 #define KSPROPERTY_TYPE_TOPOLOGY       0x10000000
1044 
1045 /*
1046 #define DEFINE_KS_GUID(GA,GB,GC,GD,GE,GF,GG,GH,GI,GJ,GK) \
1047     DEFINE_GUID(??, 0x#GA#L, 0xGB, 0xGC, 0xGD, 0xGE, 0xGF, 0xGG, 0xGH, 0xGI, 0xGJ, 0xGK) \
1048     "GA-GB-GC-GDGE-GFGGGHGIGJGK"
1049 */
1050 
1051 /* ===============================================================
1052     KS Category GUIDs
1053 
1054     BRIDGE - 0x085AFF00L, 0x62CE, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1055     CAPTURE - 0x65E8773DL, 0x8F56, 0x11D0, 0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1056     RENDER - 0x65E8773EL, 0x8F56, 0x11D0, 0xA3, 0xB9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1057     MIXER - 0xAD809C00L, 0x7B88, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1058     SPLITTER - 0x0A4252A0L, 0x7E70, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1059     DATACOMPRESSOR - 0x1E84C900L, 0x7E70, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1060     DATADECOMPRESSOR - 0x2721AE20L, 0x7E70, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1061     DATATRANSFORM - 0x2EB07EA0L, 0x7E70, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1062     COMMUNICATIONSTRANSFORM - 0xCF1DDA2CL, 0x9743, 0x11D0, 0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1063     INTERFACETRANSFORM - 0xCF1DDA2DL, 0x9743, 0x11D0, 0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1064     MEDIUMTRANSFORM - 0xCF1DDA2EL, 0x9743, 0x11D0, 0xA3, 0xEE, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1065     FILESYSTEM - 0x760FED5EL, 0x9357, 0x11D0, 0xA3, 0xCC, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1066     CLOCK - 0x53172480L, 0x4791, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1067     PROXY - 0x97EBAACAL, 0x95BD, 0x11D0, 0xA3, 0xEA, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1068     QUALITY - 0x97EBAACBL, 0x95BD, 0x11D0, 0xA3, 0xEA, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1069 */
1070 
1071 /* ===============================================================
1072     KSNAME GUIDs (defined also as KSSTRING_Xxx L"{...}"
1073 
1074     Filter - 0x9b365890L, 0x165f, 0x11d0, 0xa1, 0x95, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4
1075     Pin - 0x146F1A80L, 0x4791, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1076     Clock - 0x53172480L, 0x4791, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1077     Allocator - 0x642F5D00L, 0x4791, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1078     TopologyNode - 0x0621061AL, 0xEE75, 0x11D0, 0xB9, 0x15, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1079 */
1080 
1081 /* ===============================================================
1082     Interface GUIDs
1083 
1084     Standard - 0x1A8766A0L, 0x62CE, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1085     FileIo - 0x8C6F932CL, 0xE771, 0x11D0, 0xB8, 0xFF, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1086 */
1087 
1088 /* ===============================================================
1089     Medium Type GUIDs
1090 
1091     Standard - 0x4747B320L, 0x62CE, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1092 */
1093 
1094 /* ===============================================================
1095     Property Set GUIDs
1096 
1097     General - 0x1464EDA5L, 0x6A8F, 0x11D1, 0x9A, 0xA7, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1098     StreamIo - 0x65D003CAL, 0x1523, 0x11D2, 0xB2, 0x7A, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1099     MediaSeeking - 0xEE904F0CL, 0xD09B, 0x11D0, 0xAB, 0xE9, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96
1100     Topology - 0x720D4AC0L, 0x7533, 0x11D0, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1101     GM - 0xAF627536L, 0xE719, 0x11D2, 0x8A, 0x1D, 0x00, 0x60, 0x97, 0xD2, 0xDF, 0x5D
1102     Quality - 0xD16AD380L, 0xAC1A, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1103     Connection - 0x1D58C920L, 0xAC9B, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1104 */
1105 
1106 /* ===============================================================
1107     StreamAllocator Sets
1108 
1109     Event set - 0x75d95571L, 0x073c, 0x11d0, 0xa1, 0x61, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4
1110     Method set - 0xcf6e4341L, 0xec87, 0x11cf, 0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4
1111     Property set - 0xcf6e4342L, 0xec87, 0x11cf, 0xa1, 0x30, 0x00, 0x20, 0xaf, 0xd1, 0x56, 0xe4
1112 */
1113 
1114 /* ===============================================================
1115     StreamInterface Sets
1116 
1117     Property set - 0x1fdd8ee1L, 0x9cd3, 0x11d0, 0x82, 0xaa, 0x00, 0x00, 0xf8, 0x22, 0xfe, 0x8a
1118 */
1119 
1120 /* ===============================================================
1121     Clock Sets
1122 
1123     Property set - 0xDF12A4C0L, 0xAC17, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1124     Event sets - 0x364D8E20L, 0x62C7, 0x11CF, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00
1125 */
1126 
1127 /* ===============================================================
1128     Connection Sets
1129 
1130     Event set - 0x7f4bcbe0L, 0x9ea5, 0x11cf, 0xa5, 0xd6, 0x28, 0xdb, 0x04, 0xc1, 0x00, 0x00
1131 */
1132 
1133 /* ===============================================================
1134     Time Format GUIDs
1135 
1136     KSTIME_FORMAT_NONE  (null guid)
1137     FRAME - 0x7b785570L, 0x8c82, 0x11cf, 0xbc, 0x0c, 0x00, 0xaa, 0x00, 0xac, 0x74, 0xf6
1138     BYTE - 0x7b785571L, 0x8c82, 0x11cf, 0xbc, 0x0c, 0x00, 0xaa, 0x00, 0xac, 0x74, 0xf6
1139     SAMPLE - 0x7b785572L, 0x8c82, 0x11cf, 0xbc, 0x0c, 0x00, 0xaa, 0x00, 0xac, 0x74, 0xf6
1140     FIELD - 0x7b785573L, 0x8c82, 0x11cf, 0xbc, 0x0c, 0x00, 0xaa, 0x00, 0xac, 0x74, 0xf6
1141     MEDIA_TIME - 0x7b785574L, 0x8c82, 0x11cf, 0xbc, 0x0c, 0x00, 0xaa, 0x00, 0xac, 0x74, 0xf6
1142 */
1143 
1144 /* ===============================================================
1145     Media Type GUIDs
1146 
1147     NULL
1148     Stream -
1149     None -
1150 
1151     TODO ...
1152 */
1153 
1154 #define STATIC_KSDATAFORMAT_SPECIFIER_NONE\
1155   0x0F6417D6L, 0xC318, 0x11D0, {0xA4, 0x3F, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}
1156 DEFINE_GUIDSTRUCT("0F6417D6-C318-11D0-A43F-00A0C9223196", KSDATAFORMAT_SPECIFIER_NONE);
1157 #define KSDATAFORMAT_SPECIFIER_NONE DEFINE_GUIDNAMED(KSDATAFORMAT_SPECIFIER_NONE)
1158 
1159 /* ===============================================================
1160     KSMEMORY_TYPE_xxx
1161 
1162     WILDCARD, DONT_CARE = NULL
1163     SYSTEM - 0x091bb638L, 0x603f, 0x11d1, 0xb0, 0x67, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02
1164     USER - 0x8cb0fc28L, 0x7893, 0x11d1, 0xb0, 0x69, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02
1165     KERNEL_PAGED - 0xd833f8f8L, 0x7894, 0x11d1, 0xb0, 0x69, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02
1166     KERNEL_NONPAGED - 0x4a6d5fc4L, 0x7895, 0x11d1, 0xb0, 0x69, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02
1167     DEVICE_UNKNOWN - 0x091bb639L, 0x603f, 0x11d1, 0xb0, 0x67, 0x00, 0xa0, 0xc9, 0x06, 0x28, 0x02
1168 */
1169 
1170 /* ===============================================================
1171     Enums
1172     (values have been checked)
1173 */
1174 
1175 #ifndef _MSC_VER
1176 
1177 #define DEFINE_KSPROPERTY_ITEM(PropertyId, GetHandler,\
1178                                MinProperty,\
1179                                MinData,\
1180                                SetHandler,\
1181                                Values, RelationsCount, Relations, SupportHandler,\
1182                                SerializedSize)\
1183 {\
1184      PropertyId, {(PFNKSHANDLER)GetHandler}, MinProperty, MinData,\
1185      {(PFNKSHANDLER)SetHandler},\
1186     (PKSPROPERTY_VALUES)Values, RelationsCount, (PKSPROPERTY)Relations,\
1187     (PFNKSHANDLER)SupportHandler, (ULONG)SerializedSize\
1188 }
1189 
1190 #else
1191 
1192 #define DEFINE_KSPROPERTY_ITEM(PropertyId, GetHandler,\
1193                                MinProperty,\
1194                                MinData,\
1195                                SetHandler,\
1196                                Values, RelationsCount, Relations, SupportHandler,\
1197                                SerializedSize)\
1198 {\
1199     PropertyId, (PFNKSHANDLER)GetHandler, MinProperty, MinData,\
1200     (PFNKSHANDLER)SetHandler,\
1201     (PKSPROPERTY_VALUES)Values, RelationsCount, (PKSPROPERTY)Relations,\
1202     (PFNKSHANDLER)SupportHandler, (ULONG)SerializedSize\
1203 }
1204 
1205 #endif
1206 
1207 typedef enum {
1208   KsObjectTypeDevice,
1209   KsObjectTypeFilterFactory,
1210   KsObjectTypeFilter,
1211   KsObjectTypePin
1212 } KSOBJECTTYPE;
1213 
1214 typedef enum {
1215   KSSTATE_STOP,
1216   KSSTATE_ACQUIRE,
1217   KSSTATE_PAUSE,
1218   KSSTATE_RUN
1219 } KSSTATE, *PKSSTATE;
1220 
1221 typedef enum {
1222   KSTARGET_STATE_DISABLED,
1223   KSTARGET_STATE_ENABLED
1224 } KSTARGET_STATE;
1225 
1226 typedef enum {
1227   KSRESET_BEGIN,
1228   KSRESET_END
1229 } KSRESET;
1230 
1231 typedef enum {
1232   KSEVENTS_NONE,
1233   KSEVENTS_SPINLOCK,
1234   KSEVENTS_MUTEX,
1235   KSEVENTS_FMUTEX,
1236   KSEVENTS_FMUTEXUNSAFE,
1237   KSEVENTS_INTERRUPT,
1238   KSEVENTS_ERESOURCE
1239 } KSEVENTS_LOCKTYPE;
1240 
1241 typedef enum {
1242   KSDEGRADE_STANDARD_SIMPLE,
1243   KSDEGRADE_STANDARD_QUALITY,
1244   KSDEGRADE_STANDARD_COMPUTATION,
1245   KSDEGRADE_STANDARD_SKIP
1246 } KSDEGRADE_STANDARD;
1247 
1248 typedef enum {
1249   KSPIN_DATAFLOW_IN = 1,
1250   KSPIN_DATAFLOW_OUT
1251 } KSPIN_DATAFLOW, *PKSPIN_DATAFLOW;
1252 
1253 typedef enum {
1254   KSPIN_COMMUNICATION_NONE,
1255   KSPIN_COMMUNICATION_SINK,
1256   KSPIN_COMMUNICATION_SOURCE,
1257   KSPIN_COMMUNICATION_BOTH,
1258   KSPIN_COMMUNICATION_BRIDGE
1259 } KSPIN_COMMUNICATION, *PKSPIN_COMMUNICATION;
1260 
1261 typedef enum {
1262   KsListEntryTail,
1263   KsListEntryHead
1264 } KSLIST_ENTRY_LOCATION;
1265 
1266 typedef enum {
1267   KsStackCopyToNewLocation,
1268   KsStackReuseCurrentLocation,
1269   KsStackUseNewLocation
1270 } KSSTACK_USE;
1271 
1272 typedef enum {
1273   KsAcquireOnly,
1274   KsAcquireAndRemove,
1275   KsAcquireOnlySingleItem,
1276   KsAcquireAndRemoveOnlySingleItem
1277 } KSIRP_REMOVAL_OPERATION;
1278 
1279 typedef enum {
1280   KsInvokeOnSuccess = 1,
1281   KsInvokeOnError = 2,
1282   KsInvokeOnCancel = 4
1283 } KSCOMPLETION_INVOCATION;
1284 
1285 #if defined(_NTDDK_) && !defined(__wtypes_h__)
1286 enum VARENUM {
1287   VT_EMPTY = 0,
1288   VT_NULL = 1,
1289   VT_I2 = 2,
1290   VT_I4 = 3,
1291   VT_R4 = 4,
1292   VT_R8 = 5,
1293   VT_CY = 6,
1294   VT_DATE = 7,
1295   VT_BSTR = 8,
1296   VT_DISPATCH = 9,
1297   VT_ERROR = 10,
1298   VT_BOOL = 11,
1299   VT_VARIANT = 12,
1300   VT_UNKNOWN = 13,
1301   VT_DECIMAL = 14,
1302   VT_I1 = 16,
1303   VT_UI1 = 17,
1304   VT_UI2 = 18,
1305   VT_UI4 = 19,
1306   VT_I8 = 20,
1307   VT_UI8 = 21,
1308   VT_INT = 22,
1309   VT_UINT = 23,
1310   VT_VOID = 24,
1311   VT_HRESULT  = 25,
1312   VT_PTR = 26,
1313   VT_SAFEARRAY = 27,
1314   VT_CARRAY = 28,
1315   VT_USERDEFINED = 29,
1316   VT_LPSTR = 30,
1317   VT_LPWSTR = 31,
1318   VT_FILETIME = 64,
1319   VT_BLOB = 65,
1320   VT_STREAM = 66,
1321   VT_STORAGE = 67,
1322   VT_STREAMED_OBJECT = 68,
1323   VT_STORED_OBJECT = 69,
1324   VT_BLOB_OBJECT = 70,
1325   VT_CF = 71,
1326   VT_CLSID = 72,
1327   VT_VECTOR = 0x1000,
1328   VT_ARRAY = 0x2000,
1329   VT_BYREF = 0x4000,
1330   VT_RESERVED = 0x8000,
1331   VT_ILLEGAL = 0xffff,
1332   VT_ILLEGALMASKED = 0xfff,
1333   VT_TYPEMASK = 0xfff
1334 };
1335 #endif
1336 
1337 #define STATIC_KSDATAFORMAT_TYPE_WILDCARD      STATIC_GUID_NULL
1338 #define KSDATAFORMAT_TYPE_WILDCARD             GUID_NULL
1339 
1340 #define STATIC_KSDATAFORMAT_SUBTYPE_WILDCARD   STATIC_GUID_NULL
1341 #define KSDATAFORMAT_SUBTYPE_WILDCARD          GUID_NULL
1342 
1343 #define STATIC_KSDATAFORMAT_SPECIFIER_WILDCARD STATIC_GUID_NULL
1344 #define KSDATAFORMAT_SPECIFIER_WILDCARD        GUID_NULL
1345 
1346 /* ===============================================================
1347     Framing
1348 */
1349 
1350 typedef struct {
1351   ULONG MinFrameSize;
1352   ULONG MaxFrameSize;
1353   ULONG Stepping;
1354 } KS_FRAMING_RANGE, *PKS_FRAMING_RANGE;
1355 
1356 typedef struct {
1357   KS_FRAMING_RANGE Range;
1358   ULONG InPlaceWeight;
1359   ULONG NotInPlaceWeight;
1360 } KS_FRAMING_RANGE_WEIGHTED, *PKS_FRAMING_RANGE_WEIGHTED;
1361 
1362 typedef struct {
1363   GUID MemoryType;
1364   GUID BusType;
1365   ULONG MemoryFlags;
1366   ULONG BusFlags;
1367   ULONG Flags;
1368   ULONG Frames;
1369   ULONG FileAlignment;
1370   ULONG MemoryTypeWeight;
1371   KS_FRAMING_RANGE PhysicalRange;
1372   KS_FRAMING_RANGE_WEIGHTED FramingRange;
1373 } KS_FRAMING_ITEM, *PKS_FRAMING_ITEM;
1374 
1375 typedef struct {
1376   ULONG RatioNumerator;
1377   ULONG RatioDenominator;
1378   ULONG RatioConstantMargin;
1379 } KS_COMPRESSION, *PKS_COMPRESSION;
1380 
1381 /* ===============================================================
1382     Priorities
1383 */
1384 
1385 #define KSPRIORITY_LOW       0x00000001
1386 #define KSPRIORITY_NORMAL    0x40000000
1387 #define KSPRIORITY_HIGH      0x80000000
1388 #define KSPRIORITY_EXCLUSIVE 0xFFFFFFFF
1389 
1390 typedef struct {
1391   ULONG PriorityClass;
1392   ULONG PrioritySubClass;
1393 } KSPRIORITY, *PKSPRIORITY;
1394 
1395 /* ===============================================================
1396     Dispatch Table
1397     http://www.osronline.com/DDKx/stream/ks-struct_494j.htm
1398 */
1399 
1400 #if defined(_NTDDK_)
1401 
1402 typedef struct {
1403   PDRIVER_DISPATCH DeviceIoControl;
1404   PDRIVER_DISPATCH Read;
1405   PDRIVER_DISPATCH Write;
1406   PDRIVER_DISPATCH Flush;
1407   PDRIVER_DISPATCH Close;
1408   PDRIVER_DISPATCH QuerySecurity;
1409   PDRIVER_DISPATCH SetSecurity;
1410   PFAST_IO_DEVICE_CONTROL FastDeviceIoControl;
1411   PFAST_IO_READ FastRead;
1412   PFAST_IO_WRITE FastWrite;
1413 } KSDISPATCH_TABLE, *PKSDISPATCH_TABLE;
1414 
1415 #define KSCREATE_ITEM_IRP_STORAGE(Irp)         (*(PKSOBJECT_CREATE_ITEM*)&(Irp)->Tail.Overlay.DriverContext[0])
1416 #define KSEVENT_SET_IRP_STORAGE(Irp)           (*(const KSEVENT_SET**)&(Irp)->Tail.Overlay.DriverContext[0])
1417 #define KSEVENT_ITEM_IRP_STORAGE(Irp)          (*(const KSEVENT_ITEM**)&(Irp)->Tail.Overlay.DriverContext[3])
1418 #define KSEVENT_ENTRY_IRP_STORAGE(Irp)         (*(PKSEVENT_ENTRY*)&(Irp)->Tail.Overlay.DriverContext[0])
1419 #define KSMETHOD_SET_IRP_STORAGE(Irp)          (*(const KSMETHOD_SET**)&(Irp)->Tail.Overlay.DriverContext[0])
1420 #define KSMETHOD_ITEM_IRP_STORAGE(Irp)         (*(const KSMETHOD_ITEM**)&(Irp)->Tail.Overlay.DriverContext[3])
1421 #define KSMETHOD_TYPE_IRP_STORAGE(Irp)         (*(ULONG_PTR*)(&(Irp)->Tail.Overlay.DriverContext[2]))
1422 #define KSQUEUE_SPINLOCK_IRP_STORAGE(Irp)      (*(PKSPIN_LOCK*)&(Irp)->Tail.Overlay.DriverContext[1])
1423 #define KSPROPERTY_SET_IRP_STORAGE(Irp)        (*(const KSPROPERTY_SET**)&(Irp)->Tail.Overlay.DriverContext[0])
1424 #define KSPROPERTY_ITEM_IRP_STORAGE(Irp)       (*(const KSPROPERTY_ITEM**)&(Irp)->Tail.Overlay.DriverContext[3])
1425 #define KSPROPERTY_ATTRIBUTES_IRP_STORAGE(Irp) (*(PKSATTRIBUTE_LIST*)&(Irp)->Tail.Overlay.DriverContext[2])
1426 
1427 _IRQL_requires_max_(PASSIVE_LEVEL)
1428 typedef VOID
1429 (NTAPI *PFNREFERENCEDEVICEOBJECT)(
1430   _In_ PVOID Context);
1431 
1432 _IRQL_requires_max_(PASSIVE_LEVEL)
1433 typedef VOID
1434 (NTAPI *PFNDEREFERENCEDEVICEOBJECT)(
1435   _In_ PVOID Context);
1436 
1437 _IRQL_requires_max_(PASSIVE_LEVEL)
1438 typedef NTSTATUS
1439 (NTAPI *PFNQUERYREFERENCESTRING)(
1440   _In_ PVOID Context,
1441   _Inout_ PWCHAR *String);
1442 
1443 typedef struct {
1444   INTERFACE Interface;
1445   PFNREFERENCEDEVICEOBJECT ReferenceDeviceObject;
1446   PFNDEREFERENCEDEVICEOBJECT DereferenceDeviceObject;
1447   PFNQUERYREFERENCESTRING QueryReferenceString;
1448 } BUS_INTERFACE_REFERENCE, *PBUS_INTERFACE_REFERENCE;
1449 
1450 typedef struct {
1451   KDPC Dpc;
1452   ULONG ReferenceCount;
1453   KSPIN_LOCK AccessLock;
1454 } KSDPC_ITEM, *PKSDPC_ITEM;
1455 
1456 typedef struct {
1457   KSDPC_ITEM DpcItem;
1458   LIST_ENTRY BufferList;
1459 } KSBUFFER_ITEM, *PKSBUFFER_ITEM;
1460 
1461 #endif /* _NTDDK_ */
1462 
1463 typedef struct {
1464   GUID Manufacturer;
1465   GUID Product;
1466   GUID Component;
1467   GUID Name;
1468   ULONG Version;
1469   ULONG Revision;
1470 } KSCOMPONENTID, *PKSCOMPONENTID;
1471 
1472 #define DEFINE_KSPROPERTY_ITEM_GENERAL_COMPONENTID(Handler)\
1473     DEFINE_KSPROPERTY_ITEM(\
1474         KSPROPERTY_GENERAL_COMPONENTID,\
1475         (Handler),\
1476         sizeof(KSPROPERTY),\
1477         sizeof(KSCOMPONENTID),\
1478         NULL, NULL, 0, NULL, NULL, 0)
1479 
1480 /* ===============================================================
1481     Properties
1482 */
1483 
1484 typedef struct {
1485   GUID PropertySet;
1486   ULONG Count;
1487 } KSPROPERTY_SERIALHDR, *PKSPROPERTY_SERIALHDR;
1488 
1489 typedef struct {
1490   KSIDENTIFIER PropTypeSet;
1491   ULONG Id;
1492   ULONG PropertyLength;
1493 } KSPROPERTY_SERIAL, *PKSPROPERTY_SERIAL;
1494 
1495 typedef union {
1496   struct {
1497     LONG SignedMinimum;
1498     LONG SignedMaximum;
1499 #if defined( _KS_NO_ANONYMOUS_STRUCTURES_ )
1500   } _SIGNED;
1501 #else
1502   };
1503 #endif
1504   struct {
1505     ULONG UnsignedMinimum;
1506     ULONG UnsignedMaximum;
1507 #if defined( _KS_NO_ANONYMOUS_STRUCTURES_ )
1508   } _UNSIGNED;
1509 #else
1510   };
1511 #endif
1512 } KSPROPERTY_BOUNDS_LONG, *PKSPROPERTY_BOUNDS_LONG;
1513 
1514 typedef union {
1515   struct {
1516     LONGLONG SignedMinimum;
1517     LONGLONG SignedMaximum;
1518 #if defined( _KS_NO_ANONYMOUS_STRUCTURES_ )
1519   } _SIGNED64;
1520 #else
1521   };
1522 #endif
1523   struct {
1524 #if defined(_NTDDK_)
1525     ULONGLONG UnsignedMinimum;
1526     ULONGLONG UnsignedMaximum;
1527 #else
1528     DWORDLONG UnsignedMinimum;
1529     DWORDLONG UnsignedMaximum;
1530 #endif
1531 #if defined( _KS_NO_ANONYMOUS_STRUCTURES_ )
1532   } _UNSIGNED64;
1533 #else
1534   };
1535 #endif
1536 } KSPROPERTY_BOUNDS_LONGLONG, *PKSPROPERTY_BOUNDS_LONGLONG;
1537 
1538 typedef struct {
1539   ULONG AccessFlags;
1540   ULONG DescriptionSize;
1541   KSIDENTIFIER PropTypeSet;
1542   ULONG MembersListCount;
1543   ULONG Reserved;
1544 } KSPROPERTY_DESCRIPTION, *PKSPROPERTY_DESCRIPTION;
1545 
1546 typedef struct {
1547   ULONG MembersFlags;
1548   ULONG MembersSize;
1549   ULONG MembersCount;
1550   ULONG Flags;
1551 } KSPROPERTY_MEMBERSHEADER, *PKSPROPERTY_MEMBERSHEADER;
1552 
1553 typedef struct {
1554   KSPROPERTY_MEMBERSHEADER MembersHeader;
1555   const VOID *Members;
1556 } KSPROPERTY_MEMBERSLIST, *PKSPROPERTY_MEMBERSLIST;
1557 
1558 #define KSPROPERTY_MEMBER_RANGES        0x00000001
1559 #define KSPROPERTY_MEMBER_STEPPEDRANGES 0x00000002
1560 #define KSPROPERTY_MEMBER_VALUES        0x00000003
1561 
1562 #define KSPROPERTY_MEMBER_FLAG_DEFAULT                   0x00000001
1563 #if (NTDDI_VERSION >= NTDDI_WINXP)
1564 #define KSPROPERTY_MEMBER_FLAG_BASICSUPPORT_MULTICHANNEL 0x00000002
1565 #define KSPROPERTY_MEMBER_FLAG_BASICSUPPORT_UNIFORM      0x00000004
1566 #endif
1567 
1568 typedef struct {
1569   KSIDENTIFIER PropTypeSet;
1570   ULONG MembersListCount;
1571   _Field_size_(MembersListCount) const KSPROPERTY_MEMBERSLIST *MembersList;
1572 } KSPROPERTY_VALUES, *PKSPROPERTY_VALUES;
1573 
1574 #if defined(_NTDDK_)
1575 
1576 _IRQL_requires_max_(PASSIVE_LEVEL)
1577 typedef NTSTATUS
1578 (NTAPI *PFNKSCONTEXT_DISPATCH)(
1579   _In_ PVOID Context,
1580   _In_ PIRP Irp);
1581 
1582 _IRQL_requires_max_(PASSIVE_LEVEL)
1583 typedef NTSTATUS
1584 (NTAPI *PFNKSHANDLER)(
1585   _In_ PIRP Irp,
1586   _In_ PKSIDENTIFIER Request,
1587   _Inout_ PVOID Data);
1588 
1589 typedef struct {
1590   ULONG PropertyId;
1591   union {
1592     PFNKSHANDLER GetPropertyHandler;
1593     BOOLEAN GetSupported;
1594   };
1595   ULONG MinProperty;
1596   ULONG MinData;
1597   union {
1598     PFNKSHANDLER SetPropertyHandler;
1599     BOOLEAN SetSupported;
1600   };
1601   const KSPROPERTY_VALUES *Values;
1602   ULONG RelationsCount;
1603   _Field_size_(RelationsCount) const KSPROPERTY *Relations;
1604   PFNKSHANDLER SupportHandler;
1605   ULONG SerializedSize;
1606 } KSPROPERTY_ITEM, *PKSPROPERTY_ITEM;
1607 
1608 _IRQL_requires_max_(PASSIVE_LEVEL)
1609 typedef BOOLEAN
1610 (NTAPI *PFNKSFASTHANDLER)(
1611   _In_ PFILE_OBJECT FileObject,
1612   _In_reads_bytes_(RequestLength) PKSIDENTIFIER Request,
1613   _In_ ULONG RequestLength,
1614   _Inout_updates_bytes_(DataLength) PVOID Data,
1615   _In_ ULONG DataLength,
1616   _Out_ PIO_STATUS_BLOCK IoStatus);
1617 
1618 typedef struct {
1619   ULONG PropertyId;
1620   union {
1621     PFNKSFASTHANDLER GetPropertyHandler;
1622     BOOLEAN GetSupported;
1623   };
1624   union {
1625     PFNKSFASTHANDLER SetPropertyHandler;
1626     BOOLEAN SetSupported;
1627   };
1628   ULONG Reserved;
1629 } KSFASTPROPERTY_ITEM, *PKSFASTPROPERTY_ITEM;
1630 
1631 typedef struct {
1632   const GUID *Set;
1633   ULONG PropertiesCount;
1634   _Field_size_(PropertiesCount) const KSPROPERTY_ITEM *PropertyItem;
1635   ULONG FastIoCount;
1636   const KSFASTPROPERTY_ITEM *FastIoTable;
1637 } KSPROPERTY_SET, *PKSPROPERTY_SET;
1638 
1639 #endif /* _NTDDK_ */
1640 
1641 typedef struct {
1642   ULONG SteppingDelta;
1643   ULONG Reserved;
1644   KSPROPERTY_BOUNDS_LONG Bounds;
1645 } KSPROPERTY_STEPPING_LONG, *PKSPROPERTY_STEPPING_LONG;
1646 
1647 typedef struct {
1648 #if defined(_NTDDK_)
1649   ULONGLONG SteppingDelta;
1650 #else
1651   DWORDLONG SteppingDelta;
1652 #endif
1653   KSPROPERTY_BOUNDS_LONGLONG Bounds;
1654 } KSPROPERTY_STEPPING_LONGLONG, *PKSPROPERTY_STEPPING_LONGLONG;
1655 
1656 /* ===============================================================
1657     Allocator Framing
1658 */
1659 
1660 typedef struct {
1661   union {
1662     ULONG OptionsFlags;
1663     ULONG RequirementsFlags;
1664   };
1665 #if defined(_NTDDK_)
1666   POOL_TYPE PoolType;
1667 #else
1668   ULONG PoolType;
1669 #endif
1670   ULONG Frames;
1671   ULONG FrameSize;
1672   ULONG FileAlignment;
1673   ULONG Reserved;
1674 } KSALLOCATOR_FRAMING, *PKSALLOCATOR_FRAMING;
1675 
1676 typedef struct {
1677   ULONG CountItems;
1678   ULONG PinFlags;
1679   KS_COMPRESSION OutputCompression;
1680   ULONG PinWeight;
1681   KS_FRAMING_ITEM FramingItem[1];
1682 } KSALLOCATOR_FRAMING_EX, *PKSALLOCATOR_FRAMING_EX;
1683 
1684 #define KSALLOCATOR_REQUIREMENTF_INPLACE_MODIFIER  0x00000001
1685 #define KSALLOCATOR_REQUIREMENTF_SYSTEM_MEMORY     0x00000002
1686 #define KSALLOCATOR_REQUIREMENTF_FRAME_INTEGRITY   0x00000004
1687 #define KSALLOCATOR_REQUIREMENTF_MUST_ALLOCATE     0x00000008
1688 #define KSALLOCATOR_REQUIREMENTF_PREFERENCES_ONLY  0x80000000
1689 
1690 #define KSALLOCATOR_OPTIONF_COMPATIBLE             0x00000001
1691 #define KSALLOCATOR_OPTIONF_SYSTEM_MEMORY          0x00000002
1692 #define KSALLOCATOR_OPTIONF_VALID                  0x00000003
1693 
1694 #define KSALLOCATOR_FLAG_PARTIAL_READ_SUPPORT      0x00000010
1695 #define KSALLOCATOR_FLAG_DEVICE_SPECIFIC           0x00000020
1696 #define KSALLOCATOR_FLAG_CAN_ALLOCATE              0x00000040
1697 #define KSALLOCATOR_FLAG_INSIST_ON_FRAMESIZE_RATIO 0x00000080
1698 
1699 /* ===============================================================
1700     Quality
1701 */
1702 
1703 typedef struct {
1704   PVOID Context;
1705   ULONG Proportion;
1706   LONGLONG DeltaTime;
1707 } KSQUALITY, *PKSQUALITY;
1708 
1709 typedef struct {
1710   HANDLE QualityManager;
1711   PVOID Context;
1712 } KSQUALITY_MANAGER, *PKSQUALITY_MANAGER;
1713 
1714 typedef struct {
1715   LONGLONG PresentationStart;
1716   LONGLONG Duration;
1717   KSPIN_INTERFACE Interface;
1718   LONG Rate;
1719   ULONG Flags;
1720 } KSRATE, *PKSRATE;
1721 
1722 typedef struct {
1723   KSPROPERTY Property;
1724   KSRATE Rate;
1725 } KSRATE_CAPABILITY, *PKSRATE_CAPABILITY;
1726 
1727 typedef struct {
1728   LONGLONG Granularity;
1729   LONGLONG Error;
1730 } KSRESOLUTION, *PKSRESOLUTION;
1731 
1732 typedef struct {
1733   ULONG NotificationType;
1734   union {
1735     struct {
1736       HANDLE Event;
1737       ULONG_PTR Reserved[2];
1738     } EventHandle;
1739     struct {
1740       HANDLE Semaphore;
1741       ULONG Reserved;
1742       LONG Adjustment;
1743     } SemaphoreHandle;
1744 #if defined(_NTDDK_)
1745     struct {
1746       PVOID Event;
1747       KPRIORITY Increment;
1748       ULONG_PTR Reserved;
1749     } EventObject;
1750     struct {
1751       PVOID Semaphore;
1752       KPRIORITY Increment;
1753       LONG Adjustment;
1754     } SemaphoreObject;
1755     struct {
1756       PKDPC Dpc;
1757       ULONG ReferenceCount;
1758       ULONG_PTR Reserved;
1759     } Dpc;
1760     struct {
1761       PWORK_QUEUE_ITEM WorkQueueItem;
1762       WORK_QUEUE_TYPE WorkQueueType;
1763       ULONG_PTR Reserved;
1764     } WorkItem;
1765     struct {
1766       PWORK_QUEUE_ITEM WorkQueueItem;
1767       PKSWORKER KsWorkerObject;
1768       ULONG_PTR Reserved;
1769     } KsWorkItem;
1770 #endif
1771     struct {
1772       PVOID Unused;
1773       LONG_PTR Alignment[2];
1774     } Alignment;
1775   };
1776 } KSEVENTDATA, *PKSEVENTDATA;
1777 
1778 #define KSEVENTF_EVENT_HANDLE       0x00000001
1779 #define KSEVENTF_SEMAPHORE_HANDLE   0x00000002
1780 #if defined(_NTDDK_)
1781 #define KSEVENTF_EVENT_OBJECT       0x00000004
1782 #define KSEVENTF_SEMAPHORE_OBJECT   0x00000008
1783 #define KSEVENTF_DPC                0x00000010
1784 #define KSEVENTF_WORKITEM           0x00000020
1785 #define KSEVENTF_KSWORKITEM         0x00000080
1786 #endif
1787 
1788 
1789 #define KSEVENT_TYPE_ENABLE         0x00000001
1790 #define KSEVENT_TYPE_ONESHOT        0x00000002
1791 #define KSEVENT_TYPE_ENABLEBUFFERED 0x00000004
1792 #define KSEVENT_TYPE_SETSUPPORT     0x00000100
1793 #define KSEVENT_TYPE_BASICSUPPORT   0x00000200
1794 #define KSEVENT_TYPE_QUERYBUFFER    0x00000400
1795 
1796 #define KSEVENT_TYPE_TOPOLOGY       0x10000000
1797 
1798 typedef struct {
1799   ULONG Size;
1800   ULONG Flags;
1801   union {
1802     HANDLE ObjectHandle;
1803     PVOID ObjectPointer;
1804   };
1805   PVOID Reserved;
1806   KSEVENT Event;
1807   KSEVENTDATA EventData;
1808 } KSRELATIVEEVENT, *PKSRELATIVEEVENT;
1809 
1810 #define KSRELATIVEEVENT_FLAG_HANDLE  0x00000001
1811 #define KSRELATIVEEVENT_FLAG_POINTER 0x00000002
1812 
1813 /* ===============================================================
1814     Timing
1815 */
1816 
1817 typedef struct {
1818   KSEVENTDATA EventData;
1819   LONGLONG MarkTime;
1820 } KSEVENT_TIME_MARK, *PKSEVENT_TIME_MARK;
1821 
1822 typedef struct {
1823   KSEVENTDATA EventData;
1824   LONGLONG TimeBase;
1825   LONGLONG Interval;
1826 } KSEVENT_TIME_INTERVAL, *PKSEVENT_TIME_INTERVAL;
1827 
1828 typedef struct {
1829   LONGLONG TimeBase;
1830   LONGLONG Interval;
1831 } KSINTERVAL, *PKSINTERVAL;
1832 
1833 typedef struct {
1834   LONGLONG Time;
1835   ULONG Numerator;
1836   ULONG Denominator;
1837 } KSTIME, *PKSTIME;
1838 
1839 typedef struct {
1840   LONGLONG Time;
1841   LONGLONG SystemTime;
1842 } KSCORRELATED_TIME, *PKSCORRELATED_TIME;
1843 
1844 typedef struct {
1845   LONGLONG Duration;
1846   ULONG FrameFlags;
1847   ULONG Reserved;
1848 } KSFRAMETIME, *PKSFRAMETIME;
1849 
1850 /* ===============================================================
1851     Clocks
1852 */
1853 
1854 typedef PVOID PKSDEFAULTCLOCK;
1855 
1856 typedef struct {
1857   ULONG CreateFlags;
1858 } KSCLOCK_CREATE, *PKSCLOCK_CREATE;
1859 
1860 #if defined(_NTDDK_)
1861 
1862 _IRQL_requires_max_(PASSIVE_LEVEL)
1863 typedef LONGLONG
1864 (FASTCALL *PFNKSCLOCK_GETTIME)(
1865   _In_ PFILE_OBJECT FileObject);
1866 
1867 _IRQL_requires_max_(PASSIVE_LEVEL)
1868 typedef LONGLONG
1869 (FASTCALL *PFNKSCLOCK_CORRELATEDTIME)(
1870   _In_ PFILE_OBJECT FileObject,
1871   _Out_ PLONGLONG SystemTime);
1872 
1873 typedef struct {
1874   PFNKSCLOCK_GETTIME GetTime;
1875   PFNKSCLOCK_GETTIME GetPhysicalTime;
1876   PFNKSCLOCK_CORRELATEDTIME GetCorrelatedTime;
1877   PFNKSCLOCK_CORRELATEDTIME GetCorrelatedPhysicalTime;
1878 } KSCLOCK_FUNCTIONTABLE, *PKSCLOCK_FUNCTIONTABLE;
1879 
1880 #define DEFINE_KSPROPERTY_ITEM_CLOCK_TIME(Handler)\
1881     DEFINE_KSPROPERTY_ITEM(\
1882         KSPROPERTY_CLOCK_TIME,\
1883         (Handler),\
1884         sizeof(KSPROPERTY),\
1885         sizeof(LONGLONG),\
1886         NULL, NULL, 0, NULL, NULL, 0)
1887 
1888 #define DEFINE_KSPROPERTY_ITEM_CLOCK_PHYSICALTIME(Handler)\
1889     DEFINE_KSPROPERTY_ITEM(\
1890         KSPROPERTY_CLOCK_PHYSICALTIME,\
1891         (Handler),\
1892         sizeof(KSPROPERTY),\
1893         sizeof(LONGLONG),\
1894         NULL, NULL, 0, NULL, NULL, 0)
1895 
1896 #define DEFINE_KSPROPERTY_ITEM_CLOCK_CORRELATEDTIME(Handler)\
1897     DEFINE_KSPROPERTY_ITEM(\
1898         KSPROPERTY_CLOCK_CORRELATEDTIME,\
1899         (Handler),\
1900         sizeof(KSPROPERTY),\
1901         sizeof(KSCORRELATED_TIME),\
1902         NULL, NULL, 0, NULL, NULL, 0)
1903 
1904 #define DEFINE_KSPROPERTY_ITEM_CLOCK_CORRELATEDPHYSICALTIME(Handler)\
1905     DEFINE_KSPROPERTY_ITEM(\
1906         KSPROPERTY_CLOCK_CORRELATEDPHYSICALTIME,\
1907         (Handler),\
1908         sizeof(KSPROPERTY),\
1909         sizeof(KSCORRELATED_TIME),\
1910         NULL, NULL, 0, NULL, NULL, 0)
1911 
1912 #define DEFINE_KSPROPERTY_ITEM_CLOCK_RESOLUTION(Handler)\
1913     DEFINE_KSPROPERTY_ITEM(\
1914         KSPROPERTY_CLOCK_RESOLUTION,\
1915         (Handler),\
1916         sizeof(KSPROPERTY),\
1917         sizeof(KSRESOLUTION),\
1918         NULL, NULL, 0, NULL, NULL, 0)
1919 
1920 #define DEFINE_KSPROPERTY_ITEM_CLOCK_STATE(Handler)\
1921     DEFINE_KSPROPERTY_ITEM(\
1922         KSPROPERTY_CLOCK_STATE,\
1923         (Handler),\
1924         sizeof(KSPROPERTY),\
1925         sizeof(KSSTATE),\
1926         NULL, NULL, 0, NULL, NULL, 0)
1927 
1928 #define DEFINE_KSPROPERTY_ITEM_CLOCK_FUNCTIONTABLE(Handler)\
1929     DEFINE_KSPROPERTY_ITEM(\
1930         KSPROPERTY_CLOCK_FUNCTIONTABLE,\
1931         (Handler),\
1932         sizeof(KSPROPERTY),\
1933         sizeof(KSCLOCK_FUNCTIONTABLE),\
1934         NULL, NULL, 0, NULL, NULL, 0)
1935 
1936 #define DEFINE_KSPROPERTY_CLOCKSET(ClockSet,\
1937     PropTime, PropPhysicalTime,\
1938     PropCorrelatedTime, PropCorrelatedPhysicalTime,\
1939     PropResolution, PropState, PropFunctionTable)\
1940 DEFINE_KSPROPERTY_TABLE(ClockSet) {\
1941     DEFINE_KSPROPERTY_ITEM_CLOCK_TIME(PropTime),\
1942     DEFINE_KSPROPERTY_ITEM_CLOCK_PHYSICALTIME(PropPhysicalTime),\
1943     DEFINE_KSPROPERTY_ITEM_CLOCK_CORRELATEDTIME(PropCorrelatedTime),\
1944     DEFINE_KSPROPERTY_ITEM_CLOCK_CORRELATEDPHYSICALTIME(PropCorrelatedPhysicalTime),\
1945     DEFINE_KSPROPERTY_ITEM_CLOCK_RESOLUTION(PropResolution),\
1946     DEFINE_KSPROPERTY_ITEM_CLOCK_STATE(PropState),\
1947     DEFINE_KSPROPERTY_ITEM_CLOCK_FUNCTIONTABLE(PropFunctionTable)\
1948 }
1949 
1950 /* ===============================================================
1951     Objects ??? SORT ME!
1952 */
1953 
1954 #define KSCREATE_ITEM_SECURITYCHANGED 0x1
1955 #define KSCREATE_ITEM_WILDCARD        0x2
1956 #define KSCREATE_ITEM_NOPARAMETERS    0x4
1957 #define KSCREATE_ITEM_FREEONSTOP      0x8
1958 
1959 typedef struct {
1960   PDRIVER_DISPATCH Create;
1961   PVOID Context;
1962   UNICODE_STRING ObjectClass;
1963   PSECURITY_DESCRIPTOR SecurityDescriptor;
1964   ULONG Flags;
1965 } KSOBJECT_CREATE_ITEM, *PKSOBJECT_CREATE_ITEM;
1966 
1967 typedef struct {
1968   ULONG CreateItemsCount;
1969   _Field_size_(CreateItemsCount) PKSOBJECT_CREATE_ITEM CreateItemsList;
1970 } KSOBJECT_CREATE, *PKSOBJECT_CREATE;
1971 
1972 typedef VOID
1973 (NTAPI *PFNKSITEMFREECALLBACK)(
1974   _In_ PKSOBJECT_CREATE_ITEM CreateItem);
1975 
1976 #endif /* _NTDDK_ */
1977 
1978 typedef struct {
1979   ULONG Size;
1980   ULONG Count;
1981 } KSMULTIPLE_ITEM, *PKSMULTIPLE_ITEM;
1982 
1983 typedef struct {
1984   KSEVENT Event;
1985   PKSEVENTDATA EventData;
1986   PVOID Reserved;
1987 } KSQUERYBUFFER, *PKSQUERYBUFFER;
1988 
1989 typedef struct {
1990   PVOID Context;
1991   ULONG Status;
1992 } KSERROR, *PKSERROR;
1993 
1994 /* ===============================================================
1995     Methods
1996 */
1997 
1998 #if defined(_NTDDK_)
1999 
2000 typedef struct {
2001   ULONG MethodId;
2002   union {
2003     PFNKSHANDLER MethodHandler;
2004     BOOLEAN MethodSupported;
2005   };
2006   ULONG MinMethod;
2007   ULONG MinData;
2008   PFNKSHANDLER SupportHandler;
2009   ULONG Flags;
2010 } KSMETHOD_ITEM, *PKSMETHOD_ITEM;
2011 
2012 #ifndef _MSC_VER
2013 
2014 #define DEFINE_KSMETHOD_ITEM(MethodId, Flags,\
2015                              MethodHandler,\
2016                              MinMethod, MinData, SupportHandler)\
2017 {\
2018     MethodId, {(PFNKSHANDLER)MethodHandler}, MinMethod, MinData,\
2019     SupportHandler, Flags\
2020 }
2021 
2022 #else
2023 
2024 #define DEFINE_KSMETHOD_ITEM(MethodId, Flags,\
2025                              MethodHandler,\
2026                              MinMethod, MinData, SupportHandler)\
2027 {\
2028     MethodId, (PFNKSHANDLER)MethodHandler, MinMethod, MinData,\
2029     SupportHandler, Flags\
2030 }
2031 
2032 #endif
2033 
2034 typedef struct {
2035   ULONG MethodId;
2036   union {
2037     PFNKSFASTHANDLER MethodHandler;
2038     BOOLEAN MethodSupported;
2039   };
2040 } KSFASTMETHOD_ITEM, *PKSFASTMETHOD_ITEM;
2041 
2042 #define DEFINE_KSFASTMETHOD_ITEM(MethodId, MethodHandler)\
2043 {\
2044     MethodId, (PFNKSFASTHANDLER)MethodHandler\
2045 }
2046 
2047 typedef struct {
2048   const GUID *Set;
2049   ULONG MethodsCount;
2050   _Field_size_(MethodsCount) const KSMETHOD_ITEM *MethodItem;
2051   ULONG FastIoCount;
2052   _Field_size_(FastIoCount) const KSFASTMETHOD_ITEM *FastIoTable;
2053 } KSMETHOD_SET, *PKSMETHOD_SET;
2054 
2055 #define DEFINE_KSMETHOD_SET(Set,\
2056                             MethodsCount,\
2057                             MethodItem,\
2058                             FastIoCount,\
2059                             FastIoTable)\
2060 {\
2061     Set,\
2062     MethodsCount,\
2063     MethodItem,\
2064     FastIoCount,\
2065     FastIoTable\
2066 }
2067 
2068 #endif /* _NTDDK_ */
2069 
2070 /* ===============================================================
2071     Nodes
2072 */
2073 
2074 typedef struct {
2075   KSPROPERTY Property;
2076   ULONG NodeId;
2077   ULONG Reserved;
2078 } KSP_NODE, *PKSP_NODE;
2079 
2080 typedef struct {
2081   KSMETHOD Method;
2082   ULONG NodeID;
2083   ULONG Reserved;
2084 } KSM_NODE, *PKSM_NODE;
2085 
2086 typedef struct {
2087   KSEVENT Event;
2088   ULONG NodeId;
2089   ULONG Reserved;
2090 } KSE_NODE, *PKSE_NODE;
2091 
2092 typedef struct {
2093   ULONG CreateFlags;
2094   ULONG Node;
2095 } KSNODE_CREATE, *PKSNODE_CREATE;
2096 
2097 /* ===============================================================
2098     Events
2099 */
2100 
2101 typedef struct _KSEVENT_ENTRY KSEVENT_ENTRY, *PKSEVENT_ENTRY;
2102 
2103 #if defined(_NTDDK_)
2104 
2105 typedef NTSTATUS
2106 (NTAPI *PFNKSADDEVENT)(
2107   _In_ PIRP Irp,
2108   _In_ PKSEVENTDATA EventData,
2109   _In_ struct _KSEVENT_ENTRY *EventEntry);
2110 
2111 typedef VOID
2112 (NTAPI *PFNKSREMOVEEVENT)(
2113   _In_ PFILE_OBJECT FileObject,
2114   _In_ struct _KSEVENT_ENTRY *EventEntry);
2115 
2116 typedef struct {
2117   ULONG EventId;
2118   ULONG DataInput;
2119   ULONG ExtraEntryData;
2120   PFNKSADDEVENT AddHandler;
2121   PFNKSREMOVEEVENT RemoveHandler;
2122   PFNKSHANDLER SupportHandler;
2123 } KSEVENT_ITEM, *PKSEVENT_ITEM;
2124 
2125 typedef struct {
2126   const GUID *Set;
2127   ULONG EventsCount;
2128   _Field_size_(EventsCount) const KSEVENT_ITEM *EventItem;
2129 } KSEVENT_SET, *PKSEVENT_SET;
2130 
2131 struct _KSEVENT_ENTRY {
2132   LIST_ENTRY ListEntry;
2133   PVOID Object;
2134   union {
2135     PKSDPC_ITEM DpcItem;
2136     PKSBUFFER_ITEM BufferItem;
2137   };
2138   PKSEVENTDATA EventData;
2139   ULONG NotificationType;
2140   const KSEVENT_SET *EventSet;
2141   const KSEVENT_ITEM *EventItem;
2142   PFILE_OBJECT FileObject;
2143   ULONG SemaphoreAdjustment;
2144   ULONG Reserved;
2145   ULONG Flags;
2146 };
2147 
2148 #endif /* _NTDDK_ */
2149 
2150 /* ===============================================================
2151     Pins
2152 */
2153 
2154 #if defined(_NTDDK_)
2155 
2156 typedef struct _KSPIN  KSPIN, *PKSPIN;
2157 typedef struct _KSSTREAM_POINTER KSSTREAM_POINTER, *PKSSTREAM_POINTER;
2158 typedef struct _KSSTREAM_POINTER_OFFSET KSSTREAM_POINTER_OFFSET, *PKSSTREAM_POINTER_OFFSET;
2159 typedef struct _KSMAPPING KSMAPPING, *PKSMAPPING;
2160 typedef struct _KSPROCESSPIN KSPROCESSPIN, *PKSPROCESSPIN;
2161 
2162 #define IOCTL_KS_HANDSHAKE \
2163     CTL_CODE(FILE_DEVICE_KS, 0x007, METHOD_NEITHER, FILE_ANY_ACCESS)
2164 
2165 typedef struct {
2166   GUID ProtocolId;
2167   PVOID Argument1;
2168   PVOID Argument2;
2169 } KSHANDSHAKE, *PKSHANDSHAKE;
2170 
2171 _IRQL_requires_max_(PASSIVE_LEVEL)
2172 typedef NTSTATUS
2173 (NTAPI *PFNKSPINHANDSHAKE)(
2174   _In_ PKSPIN Pin,
2175   _In_ PKSHANDSHAKE In,
2176   _In_ PKSHANDSHAKE Out);
2177 
2178 _IRQL_requires_max_(PASSIVE_LEVEL)
2179 typedef void
2180 (NTAPI *PFNKSPINPOWER)(
2181   _In_ PKSPIN Pin,
2182   _In_ DEVICE_POWER_STATE State);
2183 
2184 typedef void
2185 (NTAPI *PFNKSPINFRAMERETURN)(
2186   _In_ PKSPIN Pin,
2187   _In_reads_bytes_opt_(Size) PVOID Data,
2188   _In_opt_ ULONG Size,
2189   _In_opt_ PMDL Mdl,
2190   _In_opt_ PVOID Context,
2191   _In_ NTSTATUS Status);
2192 
2193 _IRQL_requires_max_(DISPATCH_LEVEL)
2194 typedef void
2195 (NTAPI *PFNKSPINIRPCOMPLETION)(
2196   _In_ PKSPIN Pin,
2197   _In_ PIRP Irp);
2198 
2199 _IRQL_requires_max_(PASSIVE_LEVEL)
2200 typedef NTSTATUS
2201 (NTAPI *PFNKSPINIRP)(
2202   _In_ PKSPIN Pin,
2203   _In_ PIRP Irp);
2204 
2205 typedef NTSTATUS
2206 (NTAPI *PFNKSPIN)(
2207   _In_ PKSPIN Pin);
2208 
2209 _IRQL_requires_max_(PASSIVE_LEVEL)
2210 typedef void
2211 (NTAPI *PFNKSPINVOID)(
2212   _In_ PKSPIN Pin);
2213 
2214 _IRQL_requires_max_(DISPATCH_LEVEL)
2215 typedef void
2216 (NTAPI *PFNKSSTREAMPOINTER)(
2217   _In_ PKSSTREAM_POINTER StreamPointer);
2218 
2219 typedef struct {
2220   ULONG Count;
2221   _Field_size_(Count) PKSATTRIBUTE *Attributes;
2222 } KSATTRIBUTE_LIST, *PKSATTRIBUTE_LIST;
2223 
2224 _IRQL_requires_max_(PASSIVE_LEVEL)
2225 typedef NTSTATUS
2226 (NTAPI *PFNKSPINSETDATAFORMAT)(
2227   _In_ PKSPIN Pin,
2228   _In_opt_ PKSDATAFORMAT OldFormat,
2229   _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
2230   _In_ const KSDATARANGE* DataRange,
2231   _In_opt_ const KSATTRIBUTE_LIST* AttributeRange);
2232 
2233 _IRQL_requires_max_(PASSIVE_LEVEL)
2234 typedef NTSTATUS
2235 (NTAPI *PFNKSPINSETDEVICESTATE)(
2236   _In_ PKSPIN Pin,
2237   _In_ KSSTATE ToState,
2238   _In_ KSSTATE FromState);
2239 
2240 typedef struct _KSCLOCK_DISPATCH KSCLOCK_DISPATCH, *PKSCLOCK_DISPATCH;
2241 typedef struct _KSALLOCATOR_DISPATCH KSALLOCATOR_DISPATCH, *PKSALLOCATOR_DISPATCH;
2242 
2243 typedef struct {
2244   PFNKSPINIRP Create;
2245   PFNKSPINIRP Close;
2246   PFNKSPIN Process;
2247   PFNKSPINVOID Reset;
2248   PFNKSPINSETDATAFORMAT SetDataFormat;
2249   PFNKSPINSETDEVICESTATE SetDeviceState;
2250   PFNKSPIN Connect;
2251   PFNKSPINVOID Disconnect;
2252   const KSCLOCK_DISPATCH* Clock;
2253   const KSALLOCATOR_DISPATCH* Allocator;
2254 } KSPIN_DISPATCH, *PKSPIN_DISPATCH;
2255 
2256 _IRQL_requires_max_(DISPATCH_LEVEL)
2257 typedef BOOLEAN
2258 (NTAPI *PFNKSPINSETTIMER)(
2259   _In_ PKSPIN Pin,
2260   _In_ PKTIMER Timer,
2261   _In_ LARGE_INTEGER DueTime,
2262   _In_ PKDPC Dpc);
2263 
2264 _IRQL_requires_max_(DISPATCH_LEVEL)
2265 typedef BOOLEAN
2266 (NTAPI *PFNKSPINCANCELTIMER)(
2267   _In_ PKSPIN Pin,
2268   _In_ PKTIMER Timer);
2269 
2270 _IRQL_requires_max_(DISPATCH_LEVEL)
2271 typedef LONGLONG
2272 (FASTCALL *PFNKSPINCORRELATEDTIME)(
2273   _In_ PKSPIN Pin,
2274   _Out_ PLONGLONG SystemTime);
2275 
2276 _IRQL_requires_max_(DISPATCH_LEVEL)
2277 typedef void
2278 (NTAPI *PFNKSPINRESOLUTION)(
2279   _In_ PKSPIN Pin,
2280   _Out_ PKSRESOLUTION Resolution);
2281 
2282 struct _KSCLOCK_DISPATCH {
2283   PFNKSPINSETTIMER SetTimer;
2284   PFNKSPINCANCELTIMER CancelTimer;
2285   PFNKSPINCORRELATEDTIME CorrelatedTime;
2286   PFNKSPINRESOLUTION Resolution;
2287 };
2288 
2289 _IRQL_requires_max_(PASSIVE_LEVEL)
2290 typedef NTSTATUS
2291 (NTAPI *PFNKSPININITIALIZEALLOCATOR)(
2292   _In_ PKSPIN Pin,
2293   _In_ PKSALLOCATOR_FRAMING AllocatorFraming,
2294   _Out_ PVOID *Context);
2295 
2296 typedef PVOID
2297 (NTAPI *PFNKSDELETEALLOCATOR)(
2298   _In_ PVOID Context);
2299 
2300 typedef PVOID
2301 (NTAPI *PFNKSDEFAULTALLOCATE)(
2302   _In_ PVOID Context);
2303 
2304 typedef PVOID
2305 (NTAPI *PFNKSDEFAULTFREE)(
2306   _In_ PVOID Context,
2307   _In_ PVOID Buffer);
2308 
2309 struct _KSALLOCATOR_DISPATCH {
2310   PFNKSPININITIALIZEALLOCATOR InitializeAllocator;
2311   PFNKSDELETEALLOCATOR DeleteAllocator;
2312   PFNKSDEFAULTALLOCATE Allocate;
2313   PFNKSDEFAULTFREE Free;
2314 };
2315 
2316 typedef struct KSAUTOMATION_TABLE_ {
2317   ULONG PropertySetsCount;
2318   ULONG PropertyItemSize;
2319   _Field_size_bytes_(PropertySetsCount * PropertyItemSize) const KSPROPERTY_SET *PropertySets;
2320   ULONG MethodSetsCount;
2321   ULONG MethodItemSize;
2322   _Field_size_bytes_(MethodSetsCount * MethodItemSize) const KSMETHOD_SET *MethodSets;
2323   ULONG EventSetsCount;
2324   ULONG EventItemSize;
2325   _Field_size_bytes_(EventSetsCount * EventItemSize) const KSEVENT_SET *EventSets;
2326 #if !defined(_WIN64)
2327   PVOID Alignment;
2328 #endif
2329 } KSAUTOMATION_TABLE, *PKSAUTOMATION_TABLE;
2330 
2331 typedef struct {
2332   ULONG InterfacesCount;
2333   _Field_size_(InterfacesCount) const KSPIN_INTERFACE *Interfaces;
2334   ULONG MediumsCount;
2335   _Field_size_(MediumsCount) const KSPIN_MEDIUM *Mediums;
2336   ULONG DataRangesCount;
2337   _Field_size_(DataRangesCount) const PKSDATARANGE *DataRanges;
2338   KSPIN_DATAFLOW DataFlow;
2339   KSPIN_COMMUNICATION Communication;
2340   const GUID *Category;
2341   const GUID *Name;
2342   union {
2343     LONGLONG Reserved;
2344     struct {
2345       ULONG ConstrainedDataRangesCount;
2346       _Field_size_(ConstrainedDataRangesCount) PKSDATARANGE *ConstrainedDataRanges;
2347     };
2348   };
2349 } KSPIN_DESCRIPTOR, *PKSPIN_DESCRIPTOR;
2350 
2351 _Must_inspect_result_
2352 _IRQL_requires_max_(PASSIVE_LEVEL)
2353 typedef NTSTATUS
2354 (NTAPI *PFNKSINTERSECTHANDLER)(
2355   _In_ PIRP Irp,
2356   _In_ PKSP_PIN Pin,
2357   _In_ PKSDATARANGE DataRange,
2358   _Out_opt_ PVOID Data);
2359 
2360 _Must_inspect_result_
2361 _IRQL_requires_max_(PASSIVE_LEVEL)
2362 typedef NTSTATUS
2363 (NTAPI *PFNKSINTERSECTHANDLEREX)(
2364   _In_ PVOID Context,
2365   _In_ PIRP Irp,
2366   _In_ PKSP_PIN Pin,
2367   _In_ PKSDATARANGE DataRange,
2368   _In_ PKSDATARANGE MatchingDataRange,
2369   _In_ ULONG DataBufferSize,
2370   _Out_writes_bytes_to_opt_(DataBufferSize, *DataSize) PVOID Data,
2371   _Out_ PULONG DataSize);
2372 
2373 typedef struct {
2374   const KSPIN_DISPATCH* Dispatch;
2375   const KSAUTOMATION_TABLE* AutomationTable;
2376   KSPIN_DESCRIPTOR PinDescriptor;
2377   ULONG Flags;
2378   ULONG InstancesPossible;
2379   ULONG InstancesNecessary;
2380   const KSALLOCATOR_FRAMING_EX* AllocatorFraming;
2381   PFNKSINTERSECTHANDLEREX IntersectHandler;
2382 } KSPIN_DESCRIPTOR_EX, *PKSPIN_DESCRIPTOR_EX;
2383 
2384 #define KSFILTER_FLAG_DISPATCH_LEVEL_PROCESSING   0x00000001
2385 #define KSFILTER_FLAG_CRITICAL_PROCESSING         0x00000002
2386 #define KSFILTER_FLAG_HYPERCRITICAL_PROCESSING    0x00000004
2387 #define KSFILTER_FLAG_RECEIVE_ZERO_LENGTH_SAMPLES 0x00000008
2388 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
2389 #define KSFILTER_FLAG_DENY_USERMODE_ACCESS        0x80000000
2390 #endif
2391 
2392 #define KSPIN_FLAG_DISPATCH_LEVEL_PROCESSING KSFILTER_FLAG_DISPATCH_LEVEL_PROCESSING
2393 #define KSPIN_FLAG_CRITICAL_PROCESSING KSFILTER_FLAG_CRITICAL_PROCESSING
2394 #define KSPIN_FLAG_HYPERCRITICAL_PROCESSING KSFILTER_FLAG_HYPERCRITICAL_PROCESSING
2395 
2396 #define KSPIN_FLAG_ASYNCHRONOUS_PROCESSING              0x00000008
2397 #define KSPIN_FLAG_DO_NOT_INITIATE_PROCESSING           0x00000010
2398 #define KSPIN_FLAG_INITIATE_PROCESSING_ON_EVERY_ARRIVAL 0x00000020
2399 #define KSPIN_FLAG_FRAMES_NOT_REQUIRED_FOR_PROCESSING   0x00000040
2400 #define KSPIN_FLAG_ENFORCE_FIFO                         0x00000080
2401 
2402 #define KSPIN_FLAG_GENERATE_MAPPINGS      0x00000100
2403 #define KSPIN_FLAG_DISTINCT_TRAILING_EDGE 0x00000200
2404 
2405 #define KSPIN_FLAG_PROCESS_IN_RUN_STATE_ONLY     0x00010000
2406 #define KSPIN_FLAG_SPLITTER                      0x00020000
2407 #define KSPIN_FLAG_USE_STANDARD_TRANSPORT        0x00040000
2408 #define KSPIN_FLAG_DO_NOT_USE_STANDARD_TRANSPORT 0x00080000
2409 #define KSPIN_FLAG_FIXED_FORMAT                  0x00100000
2410 #define KSPIN_FLAG_GENERATE_EOS_EVENTS           0x00200000
2411 
2412 #define KSPIN_FLAG_RENDERER (KSPIN_FLAG_PROCESS_IN_RUN_STATE_ONLY|KSPIN_FLAG_GENERATE_EOS_EVENTS)
2413 
2414 #define KSPIN_FLAG_IMPLEMENT_CLOCK                     0x00400000
2415 #define KSPIN_FLAG_SOME_FRAMES_REQUIRED_FOR_PROCESSING 0x00800000
2416 #define KSPIN_FLAG_PROCESS_IF_ANY_IN_RUN_STATE         0x01000000
2417 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
2418 #define KSPIN_FLAG_DENY_USERMODE_ACCESS                0x80000000
2419 #endif
2420 
2421 struct _KSPIN {
2422   const KSPIN_DESCRIPTOR_EX *Descriptor;
2423   KSOBJECT_BAG Bag;
2424   PVOID Context;
2425   ULONG Id;
2426   KSPIN_COMMUNICATION Communication;
2427   BOOLEAN ConnectionIsExternal;
2428   KSPIN_INTERFACE ConnectionInterface;
2429   KSPIN_MEDIUM ConnectionMedium;
2430   KSPRIORITY ConnectionPriority;
2431   PKSDATAFORMAT ConnectionFormat;
2432   PKSMULTIPLE_ITEM AttributeList;
2433   ULONG StreamHeaderSize;
2434   KSPIN_DATAFLOW DataFlow;
2435   KSSTATE DeviceState;
2436   KSRESET ResetState;
2437   KSSTATE ClientState;
2438 };
2439 
2440 #define DEFINE_KSPROPERTY_ITEM_PIN_CINSTANCES(Handler)\
2441     DEFINE_KSPROPERTY_ITEM(\
2442         KSPROPERTY_PIN_CINSTANCES,\
2443         (Handler),\
2444         sizeof(KSP_PIN),\
2445         sizeof(KSPIN_CINSTANCES),\
2446         NULL, NULL, 0, NULL, NULL, 0)
2447 
2448 #define DEFINE_KSPROPERTY_ITEM_PIN_CTYPES(Handler)\
2449     DEFINE_KSPROPERTY_ITEM(\
2450         KSPROPERTY_PIN_CTYPES,\
2451         (Handler),\
2452         sizeof(KSPROPERTY),\
2453         sizeof(ULONG),\
2454         NULL, NULL, 0, NULL, NULL, 0)
2455 
2456 #define DEFINE_KSPROPERTY_ITEM_PIN_DATAFLOW(Handler)\
2457     DEFINE_KSPROPERTY_ITEM(\
2458         KSPROPERTY_PIN_DATAFLOW,\
2459         (Handler),\
2460         sizeof(KSP_PIN),\
2461         sizeof(KSPIN_DATAFLOW),\
2462         NULL, NULL, 0, NULL, NULL, 0)
2463 
2464 #define DEFINE_KSPROPERTY_ITEM_PIN_DATARANGES(Handler)\
2465     DEFINE_KSPROPERTY_ITEM(\
2466         KSPROPERTY_PIN_DATARANGES,\
2467         (Handler),\
2468         sizeof(KSP_PIN),\
2469         0,\
2470         NULL, NULL, 0, NULL, NULL, 0)
2471 
2472 #define DEFINE_KSPROPERTY_ITEM_PIN_DATAINTERSECTION(Handler)\
2473     DEFINE_KSPROPERTY_ITEM(\
2474         KSPROPERTY_PIN_DATAINTERSECTION,\
2475         (Handler),\
2476         sizeof(KSP_PIN) + sizeof(KSMULTIPLE_ITEM),\
2477         0,\
2478         NULL, NULL, 0, NULL, NULL, 0)
2479 
2480 #define DEFINE_KSPROPERTY_ITEM_PIN_INTERFACES(Handler)\
2481     DEFINE_KSPROPERTY_ITEM(\
2482         KSPROPERTY_PIN_INTERFACES,\
2483         (Handler),\
2484         sizeof(KSP_PIN),\
2485         0,\
2486         NULL, NULL, 0, NULL, NULL, 0)
2487 
2488 #define DEFINE_KSPROPERTY_ITEM_PIN_MEDIUMS(Handler)\
2489     DEFINE_KSPROPERTY_ITEM(\
2490         KSPROPERTY_PIN_MEDIUMS,\
2491         (Handler),\
2492         sizeof(KSP_PIN),\
2493         0,\
2494         NULL, NULL, 0, NULL, NULL, 0)
2495 
2496 #define DEFINE_KSPROPERTY_ITEM_PIN_COMMUNICATION(Handler)\
2497     DEFINE_KSPROPERTY_ITEM(\
2498         KSPROPERTY_PIN_COMMUNICATION,\
2499         (Handler),\
2500         sizeof(KSP_PIN),\
2501         sizeof(KSPIN_COMMUNICATION),\
2502         NULL, NULL, 0, NULL, NULL, 0)
2503 
2504 #define DEFINE_KSPROPERTY_ITEM_PIN_GLOBALCINSTANCES(Handler)\
2505     DEFINE_KSPROPERTY_ITEM(\
2506         KSPROPERTY_PIN_GLOBALCINSTANCES,\
2507         (Handler),\
2508         sizeof(KSP_PIN),\
2509         sizeof(KSPIN_CINSTANCES),\
2510         NULL, NULL, 0, NULL, NULL, 0)
2511 
2512 #define DEFINE_KSPROPERTY_ITEM_PIN_NECESSARYINSTANCES(Handler)\
2513     DEFINE_KSPROPERTY_ITEM(\
2514         KSPROPERTY_PIN_NECESSARYINSTANCES,\
2515         (Handler),\
2516         sizeof(KSP_PIN),\
2517         sizeof(ULONG),\
2518         NULL, NULL, 0, NULL, NULL, 0)
2519 
2520 #define DEFINE_KSPROPERTY_ITEM_PIN_PHYSICALCONNECTION(Handler)\
2521     DEFINE_KSPROPERTY_ITEM(\
2522         KSPROPERTY_PIN_PHYSICALCONNECTION,\
2523         (Handler),\
2524         sizeof(KSP_PIN),\
2525         0,\
2526         NULL, NULL, 0, NULL, NULL, 0)
2527 
2528 #define DEFINE_KSPROPERTY_ITEM_PIN_CATEGORY(Handler)\
2529     DEFINE_KSPROPERTY_ITEM(\
2530         KSPROPERTY_PIN_CATEGORY,\
2531         (Handler),\
2532         sizeof(KSP_PIN),\
2533         sizeof(GUID),\
2534         NULL, NULL, 0, NULL, NULL, 0)
2535 
2536 #define DEFINE_KSPROPERTY_ITEM_PIN_NAME(Handler)\
2537     DEFINE_KSPROPERTY_ITEM(\
2538         KSPROPERTY_PIN_NAME,\
2539         (Handler),\
2540         sizeof(KSP_PIN),\
2541         0,\
2542         NULL, NULL, 0, NULL, NULL, 0)
2543 
2544 #define DEFINE_KSPROPERTY_ITEM_PIN_CONSTRAINEDDATARANGES(Handler)\
2545     DEFINE_KSPROPERTY_ITEM(\
2546         KSPROPERTY_PIN_CONSTRAINEDDATARANGES,\
2547         (Handler),\
2548         sizeof(KSP_PIN),\
2549         0,\
2550         NULL, NULL, 0, NULL, NULL, 0)
2551 
2552 #define DEFINE_KSPROPERTY_ITEM_PIN_PROPOSEDATAFORMAT(Handler)\
2553     DEFINE_KSPROPERTY_ITEM(\
2554         KSPROPERTY_PIN_PROPOSEDATAFORMAT,\
2555         NULL,\
2556         sizeof(KSP_PIN),\
2557         sizeof(KSDATAFORMAT),\
2558         (Handler), NULL, 0, NULL, NULL, 0)
2559 
2560 #define DEFINE_KSPROPERTY_PINSET(PinSet,\
2561     PropGeneral, PropInstances, PropIntersection)\
2562 DEFINE_KSPROPERTY_TABLE(PinSet) {\
2563     DEFINE_KSPROPERTY_ITEM_PIN_CINSTANCES(PropInstances),\
2564     DEFINE_KSPROPERTY_ITEM_PIN_CTYPES(PropGeneral),\
2565     DEFINE_KSPROPERTY_ITEM_PIN_DATAFLOW(PropGeneral),\
2566     DEFINE_KSPROPERTY_ITEM_PIN_DATARANGES(PropGeneral),\
2567     DEFINE_KSPROPERTY_ITEM_PIN_DATAINTERSECTION(PropIntersection),\
2568     DEFINE_KSPROPERTY_ITEM_PIN_INTERFACES(PropGeneral),\
2569     DEFINE_KSPROPERTY_ITEM_PIN_MEDIUMS(PropGeneral),\
2570     DEFINE_KSPROPERTY_ITEM_PIN_COMMUNICATION(PropGeneral),\
2571     DEFINE_KSPROPERTY_ITEM_PIN_CATEGORY(PropGeneral),\
2572     DEFINE_KSPROPERTY_ITEM_PIN_NAME(PropGeneral)\
2573 }
2574 
2575 #define DEFINE_KSPROPERTY_PINSETCONSTRAINED(PinSet,\
2576     PropGeneral, PropInstances, PropIntersection)\
2577 DEFINE_KSPROPERTY_TABLE(PinSet) {\
2578     DEFINE_KSPROPERTY_ITEM_PIN_CINSTANCES(PropInstances),\
2579     DEFINE_KSPROPERTY_ITEM_PIN_CTYPES(PropGeneral),\
2580     DEFINE_KSPROPERTY_ITEM_PIN_DATAFLOW(PropGeneral),\
2581     DEFINE_KSPROPERTY_ITEM_PIN_DATARANGES(PropGeneral),\
2582     DEFINE_KSPROPERTY_ITEM_PIN_DATAINTERSECTION(PropIntersection),\
2583     DEFINE_KSPROPERTY_ITEM_PIN_INTERFACES(PropGeneral),\
2584     DEFINE_KSPROPERTY_ITEM_PIN_MEDIUMS(PropGeneral),\
2585     DEFINE_KSPROPERTY_ITEM_PIN_COMMUNICATION(PropGeneral),\
2586     DEFINE_KSPROPERTY_ITEM_PIN_CATEGORY(PropGeneral),\
2587     DEFINE_KSPROPERTY_ITEM_PIN_NAME(PropGeneral),\
2588     DEFINE_KSPROPERTY_ITEM_PIN_CONSTRAINEDDATARANGES(PropGeneral)\
2589 }
2590 
2591 typedef void
2592 (NTAPI *PFNKSFREE)(
2593   _In_ PVOID Data);
2594 
2595 #define DEFINE_KSPROPERTY_TABLE(tablename) \
2596   const KSPROPERTY_ITEM tablename[] =
2597 
2598 #endif /* _NTDDK_ */
2599 
2600 typedef struct {
2601   KSPIN_INTERFACE Interface;
2602   KSPIN_MEDIUM Medium;
2603   ULONG PinId;
2604   HANDLE PinToHandle;
2605   KSPRIORITY Priority;
2606 } KSPIN_CONNECT, *PKSPIN_CONNECT;
2607 
2608 /* ===============================================================
2609     Topology
2610 */
2611 
2612 typedef struct {
2613   ULONG FromNode;
2614   ULONG FromNodePin;
2615   ULONG ToNode;
2616   ULONG ToNodePin;
2617 } KSTOPOLOGY_CONNECTION, *PKSTOPOLOGY_CONNECTION;
2618 
2619 typedef struct {
2620   ULONG CategoriesCount;
2621   _Field_size_(CategoriesCount) const GUID *Categories;
2622   ULONG TopologyNodesCount;
2623   _Field_size_(TopologyNodesCount) const GUID *TopologyNodes;
2624   ULONG TopologyConnectionsCount;
2625   _Field_size_(TopologyConnectionsCount) const KSTOPOLOGY_CONNECTION *TopologyConnections;
2626   _Field_size_(TopologyNodesCount) const GUID *TopologyNodesNames;
2627   ULONG Reserved;
2628 } KSTOPOLOGY, *PKSTOPOLOGY;
2629 
2630 
2631 #define DEFINE_KSPROPERTY_ITEM_TOPOLOGY_CATEGORIES(Handler)\
2632     DEFINE_KSPROPERTY_ITEM(\
2633         KSPROPERTY_TOPOLOGY_CATEGORIES,\
2634         (Handler),\
2635         sizeof(KSPROPERTY),\
2636         0,\
2637         NULL, NULL, 0, NULL, NULL, 0)
2638 
2639 #define DEFINE_KSPROPERTY_ITEM_TOPOLOGY_NODES(Handler)\
2640     DEFINE_KSPROPERTY_ITEM(\
2641         KSPROPERTY_TOPOLOGY_NODES,\
2642         (Handler),\
2643         sizeof(KSPROPERTY),\
2644         0,\
2645         NULL, NULL, 0, NULL, NULL, 0)
2646 
2647 #define DEFINE_KSPROPERTY_ITEM_TOPOLOGY_CONNECTIONS(Handler)\
2648     DEFINE_KSPROPERTY_ITEM(\
2649         KSPROPERTY_TOPOLOGY_CONNECTIONS,\
2650         (Handler),\
2651         sizeof(KSPROPERTY),\
2652         0,\
2653         NULL, NULL, 0, NULL, NULL, 0)
2654 
2655 #define DEFINE_KSPROPERTY_ITEM_TOPOLOGY_NAME(Handler)\
2656     DEFINE_KSPROPERTY_ITEM(\
2657         KSPROPERTY_TOPOLOGY_NAME,\
2658         (Handler),\
2659         sizeof(KSP_NODE),\
2660         0,\
2661         NULL, NULL, 0, NULL, NULL, 0)
2662 
2663 #define DEFINE_KSPROPERTY_TOPOLOGYSET(TopologySet, Handler)\
2664 DEFINE_KSPROPERTY_TABLE(TopologySet) {\
2665     DEFINE_KSPROPERTY_ITEM_TOPOLOGY_CATEGORIES(Handler),\
2666     DEFINE_KSPROPERTY_ITEM_TOPOLOGY_NODES(Handler),\
2667     DEFINE_KSPROPERTY_ITEM_TOPOLOGY_CONNECTIONS(Handler),\
2668     DEFINE_KSPROPERTY_ITEM_TOPOLOGY_NAME(Handler)\
2669 }
2670 
2671 /* ===============================================================
2672     ??? SORT ME
2673 */
2674 
2675 /* TODO */
2676 typedef void* UNKNOWN;
2677 
2678 typedef PVOID
2679 (NTAPI *PFNKSINITIALIZEALLOCATOR)(
2680   _In_ PVOID InitialContext,
2681   _In_ PKSALLOCATOR_FRAMING AllocatorFraming,
2682   _Outptr_ PVOID *Context);
2683 
2684 #if defined(_NTDDK_)
2685 
2686 _IRQL_requires_max_(PASSIVE_LEVEL)
2687 typedef NTSTATUS
2688 (NTAPI *PFNKSALLOCATOR)(
2689   _In_ PIRP Irp,
2690   _In_ ULONG BufferSize,
2691   _In_ BOOLEAN InputOperation);
2692 
2693 _Must_inspect_result_
2694 _IRQL_requires_max_(PASSIVE_LEVEL)
2695 typedef NTSTATUS
2696 (NTAPI *PFNKINTERSECTHANDLEREX)(
2697   _In_ PVOID Context,
2698   _In_ PIRP Irp,
2699   _In_ PKSP_PIN Pin,
2700   _In_ PKSDATARANGE DataRange,
2701   _In_ PKSDATARANGE MatchingDataRange,
2702   _In_ ULONG DataBufferSize,
2703   _Out_writes_bytes_to_opt_(DataBufferSize, *DataSize) PVOID Data,
2704   _Out_ PULONG DataSize);
2705 
2706 typedef NTSTATUS
2707 (NTAPI *PFNALLOCATOR_ALLOCATEFRAME)(
2708   _In_ PFILE_OBJECT FileObject,
2709   _Outptr_ PVOID *Frame);
2710 
2711 typedef VOID
2712 (NTAPI *PFNALLOCATOR_FREEFRAME)(
2713   _In_ PFILE_OBJECT FileObject,
2714   _In_ PVOID Frame);
2715 
2716 typedef struct {
2717     PFNALLOCATOR_ALLOCATEFRAME  AllocateFrame;
2718     PFNALLOCATOR_FREEFRAME      FreeFrame;
2719 } KSSTREAMALLOCATOR_FUNCTIONTABLE, *PKSSTREAMALLOCATOR_FUNCTIONTABLE;
2720 
2721 #endif /* _NTDDK_ */
2722 
2723 typedef struct {
2724   KSALLOCATOR_FRAMING Framing;
2725   ULONG AllocatedFrames;
2726   ULONG Reserved;
2727 } KSSTREAMALLOCATOR_STATUS, *PKSSTREAMALLOCATOR_STATUS;
2728 
2729 typedef struct {
2730   KSALLOCATOR_FRAMING_EX Framing;
2731   ULONG AllocatedFrames;
2732   ULONG Reserved;
2733 } KSSTREAMALLOCATOR_STATUS_EX, *PKSSTREAMALLOCATOR_STATUS_EX;
2734 
2735 typedef struct {
2736   ULONG Size;
2737   ULONG TypeSpecificFlags;
2738   KSTIME PresentationTime;
2739   LONGLONG Duration;
2740   ULONG FrameExtent;
2741   ULONG DataUsed;
2742   PVOID Data;
2743   ULONG OptionsFlags;
2744 #ifdef _WIN64
2745   ULONG Reserved;
2746 #endif
2747 } KSSTREAM_HEADER, *PKSSTREAM_HEADER;
2748 
2749 #define KSSTREAM_HEADER_OPTIONSF_SPLICEPOINT        0x00000001
2750 #define KSSTREAM_HEADER_OPTIONSF_PREROLL            0x00000002
2751 #define KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY  0x00000004
2752 #define KSSTREAM_HEADER_OPTIONSF_TYPECHANGED        0x00000008
2753 #define KSSTREAM_HEADER_OPTIONSF_TIMEVALID          0x00000010
2754 #define KSSTREAM_HEADER_OPTIONSF_TIMEDISCONTINUITY  0x00000040
2755 #define KSSTREAM_HEADER_OPTIONSF_FLUSHONPAUSE       0x00000080
2756 #define KSSTREAM_HEADER_OPTIONSF_DURATIONVALID      0x00000100
2757 #define KSSTREAM_HEADER_OPTIONSF_ENDOFSTREAM        0x00000200
2758 #define KSSTREAM_HEADER_OPTIONSF_BUFFEREDTRANSFER   0x00000400
2759 #define KSSTREAM_HEADER_OPTIONSF_VRAM_DATA_TRANSFER 0x00000800
2760 #define KSSTREAM_HEADER_OPTIONSF_LOOPEDDATA         0x80000000
2761 
2762 /* ===============================================================
2763     XP / DX8
2764 */
2765 
2766 #if defined(_NTDDK_)
2767 
2768 typedef struct _KSGATE KSGATE, *PKSGATE;
2769 
2770 struct _KSGATE {
2771   LONG Count;
2772   PKSGATE NextGate;
2773 };
2774 
2775 #ifndef _NTOS_
2776 
2777 _IRQL_requires_max_(DISPATCH_LEVEL)
2778 KSDDKAPI
2779 PKSGATE
2780 NTAPI
2781 KsPinGetAndGate(
2782     _In_ PKSPIN Pin);
2783 
_IRQL_requires_max_(HIGH_LEVEL)2784 _IRQL_requires_max_(HIGH_LEVEL)
2785 static
2786 __inline
2787 void
2788 KsGateTurnInputOn(
2789     _In_opt_ PKSGATE Gate)
2790 {
2791     while (Gate && (InterlockedIncrement(&Gate->Count) == 1))
2792     {
2793         Gate = Gate->NextGate;
2794     }
2795 }
2796 
_IRQL_requires_max_(HIGH_LEVEL)2797 _IRQL_requires_max_(HIGH_LEVEL)
2798 static
2799 __inline
2800 void
2801 KsGateTurnInputOff(
2802     _In_opt_ PKSGATE Gate)
2803 {
2804     while (Gate && (InterlockedDecrement(&Gate->Count) == 0))
2805     {
2806         Gate = Gate->NextGate;
2807     }
2808 }
2809 
_IRQL_requires_max_(HIGH_LEVEL)2810 _IRQL_requires_max_(HIGH_LEVEL)
2811 static
2812 __inline
2813 BOOLEAN
2814 KsGateGetStateUnsafe(
2815     _In_ PKSGATE Gate)
2816 {
2817     ASSERT(Gate);
2818     return((BOOLEAN)(Gate->Count > 0));
2819 }
2820 
_IRQL_requires_max_(HIGH_LEVEL)2821 _IRQL_requires_max_(HIGH_LEVEL)
2822 static
2823 __inline
2824 BOOLEAN
2825 KsGateCaptureThreshold(
2826     _In_ PKSGATE Gate)
2827 {
2828     BOOLEAN captured;
2829 
2830     ASSERT(Gate);
2831 
2832     captured = (BOOLEAN)(InterlockedCompareExchange(&Gate->Count,0,1) == 1);
2833 
2834     if (captured)
2835     {
2836         KsGateTurnInputOff(Gate->NextGate);
2837     }
2838 
2839     return captured;
2840 }
2841 
_IRQL_requires_max_(HIGH_LEVEL)2842 _IRQL_requires_max_(HIGH_LEVEL)
2843 static
2844 __inline
2845 void
2846 KsGateInitialize(
2847     _In_ PKSGATE Gate,
2848     _In_ LONG InitialCount,
2849     _In_opt_ PKSGATE NextGate,
2850     _In_ BOOLEAN StateToPropagate)
2851 {
2852     ASSERT(Gate);
2853     Gate->Count = InitialCount;
2854     Gate->NextGate = NextGate;
2855 
2856     if (NextGate)
2857     {
2858         if (InitialCount > 0)
2859         {
2860             if (StateToPropagate)
2861             {
2862                 KsGateTurnInputOn(NextGate);
2863             }
2864         }
2865         else
2866         {
2867             if (!StateToPropagate)
2868             {
2869                 KsGateTurnInputOff(NextGate);
2870             }
2871         }
2872     }
2873 }
2874 
_IRQL_requires_max_(HIGH_LEVEL)2875 _IRQL_requires_max_(HIGH_LEVEL)
2876 static
2877 __inline
2878 void
2879 KsGateInitializeAnd(
2880     _In_ PKSGATE AndGate,
2881     _In_opt_ PKSGATE NextOrGate)
2882 {
2883     KsGateInitialize(AndGate,1,NextOrGate,TRUE);
2884 }
2885 
_IRQL_requires_max_(HIGH_LEVEL)2886 _IRQL_requires_max_(HIGH_LEVEL)
2887 static
2888 __inline
2889 void
2890 KsGateInitializeOr(
2891     _In_ PKSGATE OrGate,
2892     _In_opt_ PKSGATE NextAndGate)
2893 {
2894     KsGateInitialize(OrGate,0,NextAndGate,FALSE);
2895 }
2896 
_IRQL_requires_max_(HIGH_LEVEL)2897 _IRQL_requires_max_(HIGH_LEVEL)
2898 static
2899 __inline
2900 void
2901 KsGateAddOnInputToAnd(
2902     _In_ PKSGATE AndGate)
2903 {
2904     UNREFERENCED_PARAMETER (AndGate);
2905 }
2906 
_IRQL_requires_max_(HIGH_LEVEL)2907 _IRQL_requires_max_(HIGH_LEVEL)
2908 static
2909 __inline
2910 void
2911 KsGateAddOffInputToAnd(
2912     _In_ PKSGATE AndGate)
2913 {
2914     KsGateTurnInputOff(AndGate);
2915 }
2916 
_IRQL_requires_max_(HIGH_LEVEL)2917 _IRQL_requires_max_(HIGH_LEVEL)
2918 static
2919 __inline
2920 void
2921 KsGateRemoveOnInputFromAnd(
2922     _In_ PKSGATE AndGate)
2923 {
2924     UNREFERENCED_PARAMETER (AndGate);
2925 }
2926 
_IRQL_requires_max_(HIGH_LEVEL)2927 _IRQL_requires_max_(HIGH_LEVEL)
2928 static
2929 __inline
2930 void
2931 KsGateRemoveOffInputFromAnd(
2932     _In_ PKSGATE AndGate)
2933 {
2934     KsGateTurnInputOn(AndGate);
2935 }
2936 
_IRQL_requires_max_(HIGH_LEVEL)2937 _IRQL_requires_max_(HIGH_LEVEL)
2938 static
2939 __inline
2940 void
2941 KsGateAddOnInputToOr(
2942     _In_ PKSGATE OrGate)
2943 {
2944     KsGateTurnInputOn(OrGate);
2945 }
2946 
_IRQL_requires_max_(HIGH_LEVEL)2947 _IRQL_requires_max_(HIGH_LEVEL)
2948 static
2949 __inline
2950 void
2951 KsGateAddOffInputToOr(
2952     _In_ PKSGATE OrGate)
2953 {
2954     UNREFERENCED_PARAMETER (OrGate);
2955 }
2956 
_IRQL_requires_max_(HIGH_LEVEL)2957 _IRQL_requires_max_(HIGH_LEVEL)
2958 static
2959 __inline
2960 void
2961 KsGateRemoveOnInputFromOr(
2962     _In_ PKSGATE OrGate)
2963 {
2964     KsGateTurnInputOff(OrGate);
2965 }
2966 
_IRQL_requires_max_(HIGH_LEVEL)2967 _IRQL_requires_max_(HIGH_LEVEL)
2968 static
2969 __inline
2970 void
2971 KsGateRemoveOffInputFromOr(
2972     _In_ PKSGATE OrGate)
2973 {
2974     UNREFERENCED_PARAMETER (OrGate);
2975 }
2976 
_IRQL_requires_max_(HIGH_LEVEL)2977 _IRQL_requires_max_(HIGH_LEVEL)
2978 static
2979 __inline
2980 void
2981 KsGateTerminateAnd(
2982     _In_ PKSGATE AndGate)
2983 {
2984     ASSERT(AndGate);
2985     if (KsGateGetStateUnsafe(AndGate))
2986     {
2987         KsGateRemoveOnInputFromOr(AndGate->NextGate);
2988     }
2989     else
2990     {
2991         KsGateRemoveOffInputFromOr(AndGate->NextGate);
2992     }
2993 }
2994 
_IRQL_requires_max_(HIGH_LEVEL)2995 _IRQL_requires_max_(HIGH_LEVEL)
2996 static
2997 __inline
2998 void
2999 KsGateTerminateOr(
3000     _In_ PKSGATE OrGate)
3001 {
3002     ASSERT(OrGate);
3003     if (KsGateGetStateUnsafe(OrGate))
3004     {
3005         KsGateRemoveOnInputFromAnd(OrGate->NextGate);
3006     }
3007     else
3008     {
3009         KsGateRemoveOffInputFromAnd(OrGate->NextGate);
3010     }
3011 }
3012 
3013 #endif /* !_NTOS_ */
3014 
3015 struct _KSMAPPING {
3016   PHYSICAL_ADDRESS PhysicalAddress;
3017   ULONG ByteCount;
3018   ULONG Alignment;
3019 };
3020 
3021 #endif /* _NTDDK_ */
3022 
3023 typedef enum {
3024   KSSTREAM_POINTER_STATE_UNLOCKED = 0,
3025   KSSTREAM_POINTER_STATE_LOCKED
3026 } KSSTREAM_POINTER_STATE;
3027 
3028 typedef struct _KSPROCESSPIN_INDEXENTRY KSPROCESSPIN_INDEXENTRY, *PKSPROCESSPIN_INDEXENTRY;
3029 
3030 struct _KSSTREAM_POINTER_OFFSET {
3031 #if defined(_NTDDK_)
3032   union {
3033     PUCHAR Data;
3034     PKSMAPPING Mappings;
3035   };
3036 #else
3037   PUCHAR Data;
3038 #endif
3039 #if !defined(_WIN64)
3040   PVOID Alignment;
3041 #endif
3042   ULONG Count;
3043   ULONG Remaining;
3044 };
3045 
3046 #if defined(_NTDDK_)
3047 
3048 struct _KSSTREAM_POINTER {
3049   PVOID Context;
3050   PKSPIN Pin;
3051   PKSSTREAM_HEADER StreamHeader;
3052   PKSSTREAM_POINTER_OFFSET Offset;
3053   KSSTREAM_POINTER_OFFSET OffsetIn;
3054   KSSTREAM_POINTER_OFFSET OffsetOut;
3055 };
3056 
3057 struct _KSPROCESSPIN {
3058   PKSPIN Pin;
3059   PKSSTREAM_POINTER StreamPointer;
3060   PKSPROCESSPIN InPlaceCounterpart;
3061   PKSPROCESSPIN DelegateBranch;
3062   PKSPROCESSPIN CopySource;
3063   _Field_size_bytes_(BytesAvailable) PVOID Data;
3064   ULONG BytesAvailable;
3065   ULONG BytesUsed;
3066   ULONG Flags;
3067   BOOLEAN Terminate;
3068 };
3069 
3070 struct _KSPROCESSPIN_INDEXENTRY {
3071   _Field_size_(Count) PKSPROCESSPIN *Pins;
3072   ULONG Count;
3073 };
3074 
3075 #endif /* _NTDDK_ */
3076 
3077 /* ===============================================================
3078     Device Dispatch
3079 */
3080 
3081 #if defined(_NTDDK_)
3082 
3083 typedef struct _KSFILTER_DISPATCH KSFILTER_DISPATCH, *PKSFILTER_DISPATCH;
3084 typedef struct _KSDEVICE KSDEVICE, *PKSDEVICE;
3085 typedef struct _KSFILTER KSFILTER, *PKSFILTER;
3086 typedef struct _KSNODE_DESCRIPTOR KSNODE_DESCRIPTOR, *PKSNODE_DESCRIPTOR;
3087 typedef struct _KSFILTER_DESCRIPTOR KSFILTER_DESCRIPTOR, *PKSFILTER_DESCRIPTOR;
3088 typedef struct _KSDEVICE_DESCRIPTOR KSDEVICE_DESCRIPTOR, *PKSDEVICE_DESCRIPTOR;
3089 
3090 _IRQL_requires_max_(PASSIVE_LEVEL)
3091 typedef NTSTATUS
3092 (NTAPI *PFNKSDEVICECREATE)(
3093   _In_ PKSDEVICE Device);
3094 
3095 _IRQL_requires_max_(PASSIVE_LEVEL)
3096 typedef NTSTATUS
3097 (NTAPI *PFNKSDEVICEPNPSTART)(
3098   _In_ PKSDEVICE Device,
3099   _In_ PIRP Irp,
3100   _In_opt_ PCM_RESOURCE_LIST TranslatedResourceList,
3101   _In_opt_ PCM_RESOURCE_LIST UntranslatedResourceList);
3102 
3103 _IRQL_requires_max_(PASSIVE_LEVEL)
3104 typedef NTSTATUS
3105 (NTAPI *PFNKSDEVICE)(
3106   _In_ PKSDEVICE Device);
3107 
3108 _IRQL_requires_max_(PASSIVE_LEVEL)
3109 typedef NTSTATUS
3110 (NTAPI *PFNKSDEVICEIRP)(
3111   _In_ PKSDEVICE Device,
3112   _In_ PIRP Irp);
3113 
3114 _IRQL_requires_max_(PASSIVE_LEVEL)
3115 typedef VOID
3116 (NTAPI *PFNKSDEVICEIRPVOID)(
3117   _In_ PKSDEVICE Device,
3118   _In_ PIRP Irp);
3119 
3120 _IRQL_requires_max_(PASSIVE_LEVEL)
3121 typedef NTSTATUS
3122 (NTAPI *PFNKSDEVICEQUERYCAPABILITIES)(
3123   _In_ PKSDEVICE Device,
3124   _In_ PIRP Irp,
3125   _Inout_ PDEVICE_CAPABILITIES Capabilities);
3126 
3127 _IRQL_requires_max_(PASSIVE_LEVEL)
3128 typedef NTSTATUS
3129 (NTAPI *PFNKSDEVICEQUERYPOWER)(
3130   _In_ PKSDEVICE Device,
3131   _In_ PIRP Irp,
3132   _In_ DEVICE_POWER_STATE DeviceTo,
3133   _In_ DEVICE_POWER_STATE DeviceFrom,
3134   _In_ SYSTEM_POWER_STATE SystemTo,
3135   _In_ SYSTEM_POWER_STATE SystemFrom,
3136   _In_ POWER_ACTION Action);
3137 
3138 _IRQL_requires_max_(PASSIVE_LEVEL)
3139 typedef VOID
3140 (NTAPI *PFNKSDEVICESETPOWER)(
3141   _In_ PKSDEVICE Device,
3142   _In_ PIRP Irp,
3143   _In_ DEVICE_POWER_STATE To,
3144   _In_ DEVICE_POWER_STATE From);
3145 
3146 typedef struct _KSDEVICE_DISPATCH {
3147   PFNKSDEVICECREATE Add;
3148   PFNKSDEVICEPNPSTART Start;
3149   PFNKSDEVICE PostStart;
3150   PFNKSDEVICEIRP QueryStop;
3151   PFNKSDEVICEIRPVOID CancelStop;
3152   PFNKSDEVICEIRPVOID Stop;
3153   PFNKSDEVICEIRP QueryRemove;
3154   PFNKSDEVICEIRPVOID CancelRemove;
3155   PFNKSDEVICEIRPVOID Remove;
3156   PFNKSDEVICEQUERYCAPABILITIES QueryCapabilities;
3157   PFNKSDEVICEIRPVOID SurpriseRemoval;
3158   PFNKSDEVICEQUERYPOWER QueryPower;
3159   PFNKSDEVICESETPOWER SetPower;
3160   PFNKSDEVICEIRP QueryInterface;
3161 } KSDEVICE_DISPATCH, *PKSDEVICE_DISPATCH;
3162 
3163 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
3164 #define KSDEVICE_DESCRIPTOR_VERSION_2 (0x110)
3165 #define MIN_DEV_VER_FOR_FLAGS         (0x110)
3166 #endif
3167 
3168 struct _KSDEVICE {
3169   const KSDEVICE_DESCRIPTOR* Descriptor;
3170   KSOBJECT_BAG Bag;
3171   PVOID Context;
3172   PDEVICE_OBJECT FunctionalDeviceObject;
3173   PDEVICE_OBJECT PhysicalDeviceObject;
3174   PDEVICE_OBJECT NextDeviceObject;
3175   BOOLEAN Started;
3176   SYSTEM_POWER_STATE SystemPowerState;
3177   DEVICE_POWER_STATE DevicePowerState;
3178 };
3179 
3180 #endif /* _NTDDK_ */
3181 
3182 /* ===============================================================
3183     Filter Dispatch
3184 */
3185 
3186 #if defined(_NTDDK_)
3187 
3188 struct _KSFILTER {
3189   const KSFILTER_DESCRIPTOR* Descriptor;
3190   KSOBJECT_BAG Bag;
3191   PVOID Context;
3192 };
3193 
3194 _IRQL_requires_max_(PASSIVE_LEVEL)
3195 typedef void
3196 (NTAPI *PFNKSFILTERPOWER)(
3197   _In_ PKSFILTER Filter,
3198   _In_ DEVICE_POWER_STATE State);
3199 
3200 _IRQL_requires_max_(PASSIVE_LEVEL)
3201 typedef NTSTATUS
3202 (NTAPI *PFNKSFILTERIRP)(
3203   _In_ PKSFILTER Filter,
3204   _In_ PIRP Irp);
3205 
3206 typedef NTSTATUS
3207 (NTAPI *PFNKSFILTERPROCESS)(
3208   _In_ PKSFILTER Filter,
3209   _In_ PKSPROCESSPIN_INDEXENTRY ProcessPinsIndex);
3210 
3211 _IRQL_requires_max_(PASSIVE_LEVEL)
3212 typedef NTSTATUS
3213 (NTAPI *PFNKSFILTERVOID)(
3214   _In_ PKSFILTER Filter);
3215 
3216 struct _KSFILTER_DISPATCH {
3217   PFNKSFILTERIRP Create;
3218   PFNKSFILTERIRP Close;
3219   PFNKSFILTERPROCESS Process;
3220   PFNKSFILTERVOID Reset;
3221 };
3222 
3223 struct _KSNODE_DESCRIPTOR {
3224   const KSAUTOMATION_TABLE *AutomationTable;
3225   const GUID *Type;
3226   const GUID *Name;
3227 #if !defined(_WIN64)
3228   PVOID Alignment;
3229 #endif
3230 };
3231 
3232 struct _KSFILTER_DESCRIPTOR {
3233   const KSFILTER_DISPATCH *Dispatch;
3234   const KSAUTOMATION_TABLE *AutomationTable;
3235   ULONG Version;
3236   ULONG Flags;
3237   const GUID *ReferenceGuid;
3238   ULONG PinDescriptorsCount;
3239   ULONG PinDescriptorSize;
3240   _Field_size_bytes_(PinDescriptorsCount * PinDescriptorSize) const KSPIN_DESCRIPTOR_EX *PinDescriptors;
3241   ULONG CategoriesCount;
3242   _Field_size_(CategoriesCount) const GUID *Categories;
3243   ULONG NodeDescriptorsCount;
3244   ULONG NodeDescriptorSize;
3245   _Field_size_bytes_(NodeDescriptorsCount * NodeDescriptorSize) const KSNODE_DESCRIPTOR *NodeDescriptors;
3246   ULONG ConnectionsCount;
3247   _Field_size_(ConnectionsCount) const KSTOPOLOGY_CONNECTION *Connections;
3248   const KSCOMPONENTID *ComponentId;
3249 };
3250 
3251 #define KSFILTER_DESCRIPTOR_VERSION ((ULONG)-1)
3252 
3253 struct _KSDEVICE_DESCRIPTOR {
3254   const KSDEVICE_DISPATCH *Dispatch;
3255   ULONG FilterDescriptorsCount;
3256   _Field_size_(FilterDescriptorsCount) const KSFILTER_DESCRIPTOR * const *FilterDescriptors;
3257   ULONG Version;
3258   ULONG Flags;
3259 };
3260 
3261 struct _KSFILTERFACTORY {
3262   const KSFILTER_DESCRIPTOR* FilterDescriptor;
3263   KSOBJECT_BAG Bag;
3264   PVOID Context;
3265 };
3266 
3267 #define DEFINE_KSFILTER_DESCRIPTOR(descriptor)\
3268     const KSFILTER_DESCRIPTOR descriptor =
3269 
3270 #define DEFINE_KSFILTER_PIN_DESCRIPTORS(table)\
3271     SIZEOF_ARRAY(table),\
3272     sizeof(table[0]),\
3273     table
3274 
3275 #define DEFINE_KSFILTER_CATEGORIES(table)\
3276     SIZEOF_ARRAY(table),\
3277     table
3278 
3279 #define DEFINE_KSFILTER_CATEGORY(category)\
3280     1,\
3281     &(category)
3282 
3283 #define DEFINE_KSFILTER_CATEGORIES_NULL\
3284     0,\
3285     NULL
3286 
3287 #define DEFINE_KSFILTER_NODE_DESCRIPTORS(table)\
3288     SIZEOF_ARRAY(table),\
3289     sizeof(table[0]),\
3290     table
3291 
3292 #define DEFINE_KSFILTER_NODE_DESCRIPTORS_NULL\
3293     0,\
3294     sizeof(KSNODE_DESCRIPTOR),\
3295     NULL
3296 
3297 #define DEFINE_KSFILTER_CONNECTIONS(table)\
3298     SIZEOF_ARRAY(table),\
3299     table
3300 
3301 #define DEFINE_KSFILTER_DEFAULT_CONNECTIONS\
3302     0,\
3303     NULL
3304 
3305 #endif /* _NTDDK_ */
3306 
3307 /* ===============================================================
3308     Minidriver Callbacks
3309 */
3310 
3311 #if defined(_NTDDK_)
3312 
3313 typedef NTSTATUS
3314 (NTAPI *KStrMethodHandler)(
3315   IN PIRP Irp,
3316   IN PKSIDENTIFIER Request,
3317   IN OUT PVOID Data);
3318 
3319 typedef NTSTATUS
3320 (NTAPI *KStrSupportHandler)(
3321   IN PIRP Irp,
3322   IN PKSIDENTIFIER Request,
3323   IN OUT PVOID Data);
3324 
3325 #endif
3326 
3327 /* ===============================================================
3328     Allocator Functions
3329 */
3330 
3331 #if defined(_NTDDK_)
3332 
3333 _IRQL_requires_max_(PASSIVE_LEVEL)
3334 KSDDKAPI
3335 NTSTATUS
3336 NTAPI
3337 KsCreateAllocator(
3338   _In_ HANDLE ConnectionHandle,
3339   _In_ PKSALLOCATOR_FRAMING AllocatorFraming,
3340   _Out_ PHANDLE AllocatorHandle);
3341 
3342 _IRQL_requires_max_(PASSIVE_LEVEL)
3343 KSDDKAPI
3344 NTSTATUS
3345 NTAPI
3346 KsCreateDefaultAllocator(
3347   _In_ PIRP Irp);
3348 
3349 _IRQL_requires_max_(PASSIVE_LEVEL)
3350 KSDDKAPI
3351 NTSTATUS
3352 NTAPI
3353 KsValidateAllocatorCreateRequest(
3354   _In_ PIRP Irp,
3355   _Out_ PKSALLOCATOR_FRAMING *AllocatorFraming);
3356 
3357 _IRQL_requires_max_(PASSIVE_LEVEL)
3358 KSDDKAPI
3359 NTSTATUS
3360 NTAPI
3361 KsCreateDefaultAllocatorEx(
3362   _In_ PIRP Irp,
3363   _In_opt_ PVOID InitializeContext,
3364   _In_opt_ PFNKSDEFAULTALLOCATE DefaultAllocate,
3365   _In_opt_ PFNKSDEFAULTFREE DefaultFree,
3366   _In_opt_ PFNKSINITIALIZEALLOCATOR InitializeAllocator,
3367   _In_opt_ PFNKSDELETEALLOCATOR DeleteAllocator);
3368 
3369 _IRQL_requires_max_(PASSIVE_LEVEL)
3370 KSDDKAPI
3371 NTSTATUS
3372 NTAPI
3373 KsValidateAllocatorFramingEx(
3374   _In_ PKSALLOCATOR_FRAMING_EX Framing,
3375   _In_ ULONG BufferSize,
3376   _In_ const KSALLOCATOR_FRAMING_EX *PinFraming);
3377 
3378 #endif /* _NTDDK_ */
3379 
3380 /* ===============================================================
3381     Clock Functions
3382 */
3383 
3384 #if defined(_NTDDK_)
3385 
3386 _IRQL_requires_max_(DISPATCH_LEVEL)
3387 typedef BOOLEAN
3388 (NTAPI *PFNKSSETTIMER)(
3389   _In_ PVOID Context,
3390   _In_ PKTIMER Timer,
3391   _In_ LARGE_INTEGER DueTime,
3392   _In_ PKDPC Dpc);
3393 
3394 _IRQL_requires_max_(DISPATCH_LEVEL)
3395 typedef BOOLEAN
3396 (NTAPI *PFNKSCANCELTIMER)(
3397   _In_ PVOID Context,
3398   _In_ PKTIMER Timer);
3399 
3400 typedef LONGLONG
3401 (FASTCALL *PFNKSCORRELATEDTIME)(
3402   _In_ PVOID Context,
3403   _Out_ PLONGLONG SystemTime);
3404 
3405 _IRQL_requires_max_(PASSIVE_LEVEL)
3406 KSDDKAPI
3407 NTSTATUS
3408 NTAPI
3409 KsCreateClock(
3410   _In_ HANDLE ConnectionHandle,
3411   _In_ PKSCLOCK_CREATE ClockCreate,
3412   _Out_ PHANDLE ClockHandle);
3413 
3414 _IRQL_requires_max_(PASSIVE_LEVEL)
3415 KSDDKAPI
3416 NTSTATUS
3417 NTAPI
3418 KsCreateDefaultClock(
3419   _In_ PIRP Irp,
3420   _In_ PKSDEFAULTCLOCK DefaultClock);
3421 
3422 _IRQL_requires_max_(PASSIVE_LEVEL)
3423 KSDDKAPI
3424 NTSTATUS
3425 NTAPI
3426 KsAllocateDefaultClock(
3427   _Out_ PKSDEFAULTCLOCK *DefaultClock);
3428 
3429 _IRQL_requires_max_(PASSIVE_LEVEL)
3430 KSDDKAPI
3431 NTSTATUS
3432 NTAPI
3433 KsAllocateDefaultClockEx(
3434   _Out_ PKSDEFAULTCLOCK *DefaultClock,
3435   _In_opt_ PVOID Context,
3436   _In_opt_ PFNKSSETTIMER SetTimer,
3437   _In_opt_ PFNKSCANCELTIMER CancelTimer,
3438   _In_opt_ PFNKSCORRELATEDTIME CorrelatedTime,
3439   _In_opt_ const KSRESOLUTION *Resolution,
3440   _In_ ULONG Flags);
3441 
3442 _IRQL_requires_max_(PASSIVE_LEVEL)
3443 KSDDKAPI
3444 VOID
3445 NTAPI
3446 KsFreeDefaultClock(
3447   _In_ PKSDEFAULTCLOCK DefaultClock);
3448 
3449 _IRQL_requires_max_(PASSIVE_LEVEL)
3450 KSDDKAPI
3451 NTSTATUS
3452 NTAPI
3453 KsValidateClockCreateRequest(
3454   _In_ PIRP Irp,
3455   _Outptr_ PKSCLOCK_CREATE *ClockCreate);
3456 
3457 _IRQL_requires_max_(DISPATCH_LEVEL)
3458 KSDDKAPI
3459 KSSTATE
3460 NTAPI
3461 KsGetDefaultClockState(
3462   _In_ PKSDEFAULTCLOCK DefaultClock);
3463 
3464 _IRQL_requires_max_(DISPATCH_LEVEL)
3465 KSDDKAPI
3466 VOID
3467 NTAPI
3468 KsSetDefaultClockState(
3469   _In_ PKSDEFAULTCLOCK DefaultClock,
3470   _In_ KSSTATE State);
3471 
3472 _IRQL_requires_max_(DISPATCH_LEVEL)
3473 KSDDKAPI
3474 LONGLONG
3475 NTAPI
3476 KsGetDefaultClockTime(
3477   _In_ PKSDEFAULTCLOCK DefaultClock);
3478 
3479 _IRQL_requires_max_(DISPATCH_LEVEL)
3480 KSDDKAPI
3481 VOID
3482 NTAPI
3483 KsSetDefaultClockTime(
3484   _In_ PKSDEFAULTCLOCK DefaultClock,
3485   _In_ LONGLONG Time);
3486 
3487 #endif /* _NTDDK_ */
3488 
3489 /* ===============================================================
3490     Method Functions
3491 */
3492 
3493 /* Method sets - TODO: Make into macros! */
3494 #if defined(_NTDDK_)
3495 
3496 #if 0
3497 
3498 VOID
3499 KSMETHOD_SET_IRP_STORAGE(
3500   IN IRP Irp);
3501 
3502 VOID
3503 KSMETHOD_ITEM_IRP_STORAGE(
3504   IN IRP Irp);
3505 
3506 VOID
3507 KSMETHOD_TYPE_IRP_STORAGE(
3508   IN IRP Irp);
3509 
3510 #endif
3511 
3512 _IRQL_requires_max_(PASSIVE_LEVEL)
3513 KSDDKAPI
3514 NTSTATUS
3515 NTAPI
3516 KsMethodHandler(
3517   _In_ PIRP Irp,
3518   _In_ ULONG MethodSetsCount,
3519   _In_reads_(MethodSetsCount) const KSMETHOD_SET* MethodSet);
3520 
3521 _IRQL_requires_max_(PASSIVE_LEVEL)
3522 KSDDKAPI
3523 NTSTATUS
3524 NTAPI
3525 KsMethodHandlerWithAllocator(
3526   _In_ PIRP Irp,
3527   _In_ ULONG MethodSetsCount,
3528   _In_reads_(MethodSetsCount) const KSMETHOD_SET* MethodSet,
3529   _In_opt_ PFNKSALLOCATOR Allocator,
3530   _In_opt_ ULONG MethodItemSize);
3531 
3532 _IRQL_requires_max_(PASSIVE_LEVEL)
3533 KSDDKAPI
3534 BOOLEAN
3535 NTAPI
3536 KsFastMethodHandler(
3537   _In_ PFILE_OBJECT FileObject,
3538   _In_reads_bytes_(MethodLength) PKSMETHOD UNALIGNED Method,
3539   _In_ ULONG MethodLength,
3540   _Inout_updates_bytes_(DataLength) PVOID UNALIGNED Data,
3541   _In_ ULONG DataLength,
3542   _Out_ PIO_STATUS_BLOCK IoStatus,
3543   _In_ ULONG MethodSetsCount,
3544   _In_reads_(MethodSetsCount) const KSMETHOD_SET *MethodSet);
3545 
3546 #endif /* _NTDDK_ */
3547 
3548 /* ===============================================================
3549     Property Functions
3550 */
3551 
3552 #if defined(_NTDDK_)
3553 
3554 _IRQL_requires_max_(PASSIVE_LEVEL)
3555 KSDDKAPI
3556 NTSTATUS
3557 NTAPI
3558 KsPropertyHandler(
3559   _In_ PIRP Irp,
3560   _In_ ULONG PropertySetsCount,
3561   _In_reads_(PropertySetsCount) const KSPROPERTY_SET *PropertySet);
3562 
3563 _IRQL_requires_max_(PASSIVE_LEVEL)
3564 KSDDKAPI
3565 NTSTATUS
3566 NTAPI
3567 KsPropertyHandlerWithAllocator(
3568   _In_ PIRP Irp,
3569   _In_ ULONG PropertySetsCount,
3570   _In_reads_(PropertySetsCount) const KSPROPERTY_SET* PropertySet,
3571   _In_opt_ PFNKSALLOCATOR Allocator,
3572   _In_opt_ ULONG PropertyItemSize);
3573 
3574 _IRQL_requires_max_(PASSIVE_LEVEL)
3575 KSDDKAPI
3576 NTSTATUS
3577 NTAPI
3578 KsUnserializeObjectPropertiesFromRegistry(
3579   _In_ PFILE_OBJECT FileObject,
3580   _In_opt_ HANDLE ParentKey,
3581   _In_opt_ PUNICODE_STRING RegistryPath);
3582 
3583 _IRQL_requires_max_(PASSIVE_LEVEL)
3584 KSDDKAPI
3585 BOOLEAN
3586 NTAPI
3587 KsFastPropertyHandler(
3588   _In_ PFILE_OBJECT FileObject,
3589   _In_reads_bytes_(PropertyLength) PKSPROPERTY UNALIGNED Property,
3590   _In_ ULONG PropertyLength,
3591   _In_reads_bytes_(DataLength) PVOID UNALIGNED Data,
3592   _In_ ULONG DataLength,
3593   _Out_ PIO_STATUS_BLOCK IoStatus,
3594   _In_ ULONG PropertySetsCount,
3595   _In_reads_(PropertySetsCount) const KSPROPERTY_SET *PropertySet);
3596 
3597 #endif /* _NTDDK_ */
3598 
3599 /* ===============================================================
3600     Event Functions
3601 */
3602 
3603 #if defined(_NTDDK_)
3604 
3605 #define KSPROBE_STREAMREAD      0x00000000
3606 #define KSPROBE_STREAMWRITE     0x00000001
3607 #define KSPROBE_ALLOCATEMDL     0x00000010
3608 #define KSPROBE_PROBEANDLOCK    0x00000020
3609 #define KSPROBE_SYSTEMADDRESS   0x00000040
3610 #define KSPROBE_MODIFY          0x00000200
3611 #define KSPROBE_STREAMWRITEMODIFY (KSPROBE_MODIFY | KSPROBE_STREAMWRITE)
3612 #define KSPROBE_ALLOWFORMATCHANGE 0x00000080
3613 
3614 #define KSSTREAM_READ             KSPROBE_STREAMREAD
3615 #define KSSTREAM_WRITE            KSPROBE_STREAMWRITE
3616 #define KSSTREAM_PAGED_DATA       0x00000000
3617 #define KSSTREAM_NONPAGED_DATA    0x00000100
3618 #define KSSTREAM_SYNCHRONOUS      0x00001000
3619 #define KSSTREAM_FAILUREEXCEPTION 0x00002000
3620 
3621 _IRQL_requires_max_(DISPATCH_LEVEL)
3622 typedef BOOLEAN
3623 (NTAPI *PFNKSGENERATEEVENTCALLBACK)(
3624   _In_ PVOID Context,
3625   _In_ PKSEVENT_ENTRY EventEntry);
3626 
3627 KSDDKAPI
3628 NTSTATUS
3629 NTAPI
3630 KsGenerateEvent(
3631   _In_ PKSEVENT_ENTRY EntryEvent);
3632 
3633 _IRQL_requires_max_(DISPATCH_LEVEL)
3634 KSDDKAPI
3635 void
3636 NTAPI
3637 KsGenerateEvents(
3638   _In_ PVOID Object,
3639   _In_opt_ const GUID *EventSet,
3640   _In_ ULONG EventId,
3641   _In_ ULONG DataSize,
3642   _In_reads_bytes_opt_(DataSize) PVOID Data,
3643   _In_opt_ PFNKSGENERATEEVENTCALLBACK CallBack,
3644   _In_opt_ PVOID CallBackContext);
3645 
3646 _IRQL_requires_max_(PASSIVE_LEVEL)
3647 KSDDKAPI
3648 NTSTATUS
3649 NTAPI
3650 KsEnableEventWithAllocator(
3651   _In_ PIRP Irp,
3652   _In_ ULONG EventSetsCount,
3653   _In_reads_(EventSetsCount) const KSEVENT_SET* EventSet,
3654   _Inout_opt_ PLIST_ENTRY EventsList,
3655   _In_opt_ KSEVENTS_LOCKTYPE EventsFlags,
3656   _In_opt_ PVOID EventsLock,
3657   _In_opt_ PFNKSALLOCATOR Allocator,
3658   _In_opt_ ULONG EventItemSize);
3659 
3660 KSDDKAPI
3661 NTSTATUS
3662 NTAPI
3663 KsGenerateDataEvent(
3664   _In_ PKSEVENT_ENTRY EventEntry,
3665   _In_ ULONG DataSize,
3666   _In_reads_bytes_(DataSize) PVOID Data);
3667 
3668 _IRQL_requires_max_(PASSIVE_LEVEL)
3669 KSDDKAPI
3670 NTSTATUS
3671 NTAPI
3672 KsEnableEvent(
3673   _In_ PIRP Irp,
3674   _In_ ULONG EventSetsCount,
3675   _In_reads_(EventSetsCount) KSEVENT_SET *EventSet,
3676   _Inout_opt_ PLIST_ENTRY EventsList,
3677   _In_opt_ KSEVENTS_LOCKTYPE EventsFlags,
3678   _In_opt_ PVOID EventsLock);
3679 
3680 _IRQL_requires_max_(PASSIVE_LEVEL)
3681 KSDDKAPI
3682 VOID
3683 NTAPI
3684 KsDiscardEvent(
3685   _In_ PKSEVENT_ENTRY EventEntry);
3686 
3687 _IRQL_requires_max_(PASSIVE_LEVEL)
3688 KSDDKAPI
3689 NTSTATUS
3690 NTAPI
3691 KsDisableEvent(
3692   _In_ PIRP Irp,
3693   _Inout_ PLIST_ENTRY EventsList,
3694   _In_ KSEVENTS_LOCKTYPE EventsFlags,
3695   _In_ PVOID EventsLock);
3696 
3697 _IRQL_requires_max_(PASSIVE_LEVEL)
3698 KSDDKAPI
3699 VOID
3700 NTAPI
3701 KsFreeEventList(
3702   _In_ PFILE_OBJECT FileObject,
3703   _Inout_ PLIST_ENTRY EventsList,
3704   _In_ KSEVENTS_LOCKTYPE EventsFlags,
3705   _In_ PVOID EventsLock);
3706 
3707 /* ===============================================================
3708     Topology Functions
3709 */
3710 
3711 _IRQL_requires_max_(PASSIVE_LEVEL)
3712 KSDDKAPI
3713 NTSTATUS
3714 NTAPI
3715 KsValidateTopologyNodeCreateRequest(
3716   _In_ PIRP Irp,
3717   _In_ PKSTOPOLOGY Topology,
3718   _Out_ PKSNODE_CREATE *NodeCreate);
3719 
3720 _IRQL_requires_max_(PASSIVE_LEVEL)
3721 KSDDKAPI
3722 NTSTATUS
3723 NTAPI
3724 KsCreateTopologyNode(
3725   _In_ HANDLE ParentHandle,
3726   _In_ PKSNODE_CREATE NodeCreate,
3727   _In_ ACCESS_MASK DesiredAccess,
3728   _Out_ PHANDLE NodeHandle);
3729 
3730 _IRQL_requires_max_(PASSIVE_LEVEL)
3731 KSDDKAPI
3732 NTSTATUS
3733 NTAPI
3734 KsTopologyPropertyHandler(
3735   _In_ PIRP Irp,
3736   _In_ PKSPROPERTY Property,
3737   _Inout_ PVOID Data,
3738   _In_ const KSTOPOLOGY *Topology);
3739 
3740 /* ===============================================================
3741     Connectivity Functions
3742 */
3743 
3744 _IRQL_requires_max_(PASSIVE_LEVEL)
3745 KSDDKAPI
3746 NTSTATUS
3747 NTAPI
3748 KsCreatePin(
3749   _In_ HANDLE FilterHandle,
3750   _In_ PKSPIN_CONNECT Connect,
3751   _In_ ACCESS_MASK DesiredAccess,
3752   _Out_ PHANDLE ConnectionHandle);
3753 
3754 _IRQL_requires_max_(PASSIVE_LEVEL)
3755 KSDDKAPI
3756 NTSTATUS
3757 NTAPI
3758 KsValidateConnectRequest(
3759   _In_ PIRP Irp,
3760   _In_ ULONG DescriptorsCount,
3761   _In_reads_(DescriptorsCount) KSPIN_DESCRIPTOR *Descriptor,
3762   _Out_ PKSPIN_CONNECT *Connect);
3763 
3764 _IRQL_requires_max_(PASSIVE_LEVEL)
3765 KSDDKAPI
3766 NTSTATUS
3767 NTAPI
3768 KsPinPropertyHandler(
3769   _In_ PIRP Irp,
3770   _In_ PKSPROPERTY Property,
3771   _Inout_ PVOID Data,
3772   _In_ ULONG DescriptorsCount,
3773   _In_reads_(DescriptorsCount) const KSPIN_DESCRIPTOR *Descriptor);
3774 
3775 _Must_inspect_result_
3776 _IRQL_requires_max_(PASSIVE_LEVEL)
3777 KSDDKAPI
3778 NTSTATUS
3779 NTAPI
3780 KsPinDataIntersection(
3781   _In_ PIRP Irp,
3782   _In_ PKSP_PIN Pin,
3783   _Out_opt_ PVOID Data,
3784   _In_ ULONG DescriptorsCount,
3785   _In_reads_(DescriptorsCount) const KSPIN_DESCRIPTOR *Descriptor,
3786   _In_ PFNKSINTERSECTHANDLER IntersectHandler);
3787 
3788 _Must_inspect_result_
3789 _IRQL_requires_max_(PASSIVE_LEVEL)
3790 KSDDKAPI
3791 NTSTATUS
3792 NTAPI
3793 KsPinDataIntersectionEx(
3794   _In_ PIRP Irp,
3795   _In_ PKSP_PIN Pin,
3796   _Out_ PVOID Data,
3797   _In_ ULONG DescriptorsCount,
3798   _In_reads_bytes_(DescriptorsCount * DescriptorSize) const KSPIN_DESCRIPTOR *Descriptor,
3799   _In_ ULONG DescriptorSize,
3800   _In_opt_ PFNKSINTERSECTHANDLEREX IntersectHandler,
3801   _In_opt_ PVOID HandlerContext);
3802 
3803 _IRQL_requires_max_(PASSIVE_LEVEL)
3804 KSDDKAPI
3805 PKSFILTER
3806 NTAPI
3807 KsPinGetParentFilter(
3808   _In_ PKSPIN Pin);
3809 
3810 _IRQL_requires_max_(PASSIVE_LEVEL)
3811 KSDDKAPI
3812 PKSPIN
3813 NTAPI
3814 KsPinGetNextSiblingPin(
3815   _In_ PKSPIN Pin);
3816 
3817 _IRQL_requires_max_(DISPATCH_LEVEL)
3818 KSDDKAPI
3819 PKSSTREAM_POINTER
3820 NTAPI
3821 KsPinGetLeadingEdgeStreamPointer(
3822   _In_ PKSPIN Pin,
3823   _In_ KSSTREAM_POINTER_STATE State);
3824 
3825 _IRQL_requires_max_(DISPATCH_LEVEL)
3826 KSDDKAPI
3827 NTSTATUS
3828 NTAPI
3829 KsStreamPointerSetStatusCode(
3830     _In_ PKSSTREAM_POINTER StreamPointer,
3831     _In_ NTSTATUS Status
3832 );
3833 
3834 _IRQL_requires_max_(DISPATCH_LEVEL)
3835 KSDDKAPI
3836 void
3837 NTAPI
3838 KsStreamPointerDelete(
3839     _In_ PKSSTREAM_POINTER StreamPointer
3840 );
3841 
3842 _IRQL_requires_max_(DISPATCH_LEVEL)
3843 KSDDKAPI
3844 NTSTATUS
3845 NTAPI
3846 KsStreamPointerClone(
3847     _In_ PKSSTREAM_POINTER StreamPointer,
3848     _In_opt_ PFNKSSTREAMPOINTER CancelCallback,
3849     _In_ ULONG ContextSize,
3850     _Out_ PKSSTREAM_POINTER* CloneStreamPointer
3851 );
3852 
3853 
3854 /* Does this belong here? */
3855 
3856 _IRQL_requires_max_(PASSIVE_LEVEL)
3857 KSDDKAPI
3858 NTSTATUS
3859 NTAPI
3860 KsHandleSizedListQuery(
3861   _In_ PIRP Irp,
3862   _In_ ULONG DataItemsCount,
3863   _In_ ULONG DataItemSize,
3864   _In_reads_bytes_(DataItemsCount * DataItemSize) const VOID *DataItems);
3865 
3866 /* ===============================================================
3867     IRP Helper Functions
3868 */
3869 
3870 _IRQL_requires_max_(DISPATCH_LEVEL)
3871 typedef NTSTATUS
3872 (NTAPI *PFNKSIRPLISTCALLBACK)(
3873   _In_ PIRP Irp,
3874   _In_ PVOID Context);
3875 
3876 _IRQL_requires_max_(PASSIVE_LEVEL)
3877 KSDDKAPI
3878 NTSTATUS
3879 NTAPI
3880 KsAcquireResetValue(
3881   _In_ PIRP Irp,
3882   _Out_ KSRESET *ResetValue);
3883 
3884 _IRQL_requires_max_(DISPATCH_LEVEL)
3885 KSDDKAPI
3886 VOID
3887 NTAPI
3888 KsAddIrpToCancelableQueue(
3889   _Inout_ PLIST_ENTRY QueueHead,
3890   _In_ PKSPIN_LOCK SpinLock,
3891   _In_ PIRP Irp,
3892   _In_ KSLIST_ENTRY_LOCATION ListLocation,
3893   _In_opt_ PDRIVER_CANCEL DriverCancel);
3894 
3895 _IRQL_requires_max_(PASSIVE_LEVEL)
3896 KSDDKAPI
3897 NTSTATUS
3898 NTAPI
3899 KsAddObjectCreateItemToDeviceHeader(
3900   _In_ KSDEVICE_HEADER Header,
3901   _In_ PDRIVER_DISPATCH Create,
3902   _In_ PVOID Context,
3903   _In_ PWSTR ObjectClass,
3904   _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor);
3905 
3906 _IRQL_requires_max_(PASSIVE_LEVEL)
3907 KSDDKAPI
3908 NTSTATUS
3909 NTAPI
3910 KsAddObjectCreateItemToObjectHeader(
3911   _In_ KSOBJECT_HEADER Header,
3912   _In_ PDRIVER_DISPATCH Create,
3913   _In_ PVOID Context,
3914   _In_ PWSTR ObjectClass,
3915   _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor);
3916 
3917 _IRQL_requires_max_(APC_LEVEL)
3918 KSDDKAPI
3919 NTSTATUS
3920 NTAPI
3921 KsAllocateDeviceHeader(
3922   _Out_ KSDEVICE_HEADER *Header,
3923   _In_ ULONG ItemsCount,
3924   _In_reads_opt_(ItemsCount) PKSOBJECT_CREATE_ITEM ItemsList);
3925 
3926 _IRQL_requires_max_(PASSIVE_LEVEL)
3927 KSDDKAPI
3928 NTSTATUS
3929 NTAPI
3930 KsAllocateExtraData(
3931   _Inout_ PIRP Irp,
3932   _In_ ULONG ExtraSize,
3933   _Out_ PVOID *ExtraBuffer);
3934 
3935 _IRQL_requires_max_(PASSIVE_LEVEL)
3936 KSDDKAPI
3937 NTSTATUS
3938 NTAPI
3939 KsAllocateObjectCreateItem(
3940   _In_ KSDEVICE_HEADER Header,
3941   _In_ PKSOBJECT_CREATE_ITEM CreateItem,
3942   _In_ BOOLEAN AllocateEntry,
3943   _In_opt_ PFNKSITEMFREECALLBACK ItemFreeCallback);
3944 
3945 _IRQL_requires_max_(APC_LEVEL)
3946 KSDDKAPI
3947 NTSTATUS
3948 NTAPI
3949 KsAllocateObjectHeader(
3950   _Out_ KSOBJECT_HEADER *Header,
3951   _In_ ULONG ItemsCount,
3952   _In_reads_opt_(ItemsCount) PKSOBJECT_CREATE_ITEM ItemsList,
3953   _In_ PIRP Irp,
3954   _In_ KSDISPATCH_TABLE *Table);
3955 
3956 _IRQL_requires_max_(DISPATCH_LEVEL)
3957 KSDDKAPI
3958 VOID
3959 NTAPI
3960 KsCancelIo(
3961   _Inout_ PLIST_ENTRY QueueHead,
3962   _In_ PKSPIN_LOCK SpinLock);
3963 
3964 _IRQL_requires_max_(DISPATCH_LEVEL)
3965 KSDDKAPI
3966 VOID
3967 NTAPI
3968 KsCancelRoutine(
3969   _In_ PDEVICE_OBJECT DeviceObject,
3970   _In_ PIRP Irp);
3971 
3972 _IRQL_requires_max_(PASSIVE_LEVEL)
3973 KSDDKAPI
3974 NTSTATUS
3975 NTAPI
3976 KsDefaultDeviceIoCompletion(
3977   _In_ PDEVICE_OBJECT DeviceObject,
3978   _In_ PIRP Irp);
3979 
3980 _IRQL_requires_max_(PASSIVE_LEVEL)
3981 KSDDKAPI
3982 BOOLEAN
3983 NTAPI
3984 KsDispatchFastIoDeviceControlFailure(
3985   _In_ PFILE_OBJECT FileObject,
3986   _In_ BOOLEAN Wait,
3987   _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer,
3988   _In_ ULONG InputBufferLength,
3989   _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
3990   _In_ ULONG OutputBufferLength,
3991   _In_ ULONG IoControlCode,
3992   _Out_ PIO_STATUS_BLOCK IoStatus,
3993   _In_ PDEVICE_OBJECT DeviceObject);   /* always return false */
3994 
3995 _IRQL_requires_max_(PASSIVE_LEVEL)
3996 KSDDKAPI
3997 BOOLEAN
3998 NTAPI
3999 KsDispatchFastReadFailure(
4000   _In_ PFILE_OBJECT FileObject,
4001   _In_ PLARGE_INTEGER FileOffset,
4002   _In_ ULONG Length,
4003   _In_ BOOLEAN Wait,
4004   _In_ ULONG LockKey,
4005   _Out_ PVOID Buffer,
4006   _Out_ PIO_STATUS_BLOCK IoStatus,
4007   _In_ PDEVICE_OBJECT DeviceObject);   /* always return false */
4008 
4009 /* This function does the same as the above */
4010 #define KsDispatchFastWriteFailure KsDispatchFastReadFailure
4011 
4012 _IRQL_requires_max_(PASSIVE_LEVEL)
4013 KSDDKAPI
4014 NTSTATUS
4015 NTAPI
4016 KsDispatchInvalidDeviceRequest(
4017   _In_ PDEVICE_OBJECT DeviceObject,
4018   _In_ PIRP Irp);
4019 
4020 _IRQL_requires_max_(PASSIVE_LEVEL)
4021 KSDDKAPI
4022 NTSTATUS
4023 NTAPI
4024 KsDispatchIrp(
4025   _In_ PDEVICE_OBJECT DeviceObject,
4026   _In_ PIRP Irp);
4027 
4028 _IRQL_requires_max_(PASSIVE_LEVEL)
4029 KSDDKAPI
4030 NTSTATUS
4031 NTAPI
4032 KsDispatchSpecificMethod(
4033   _In_ PIRP Irp,
4034   _In_ PFNKSHANDLER Handler);
4035 
4036 _IRQL_requires_max_(PASSIVE_LEVEL)
4037 KSDDKAPI
4038 NTSTATUS
4039 NTAPI
4040 KsDispatchSpecificProperty(
4041   _In_ PIRP Irp,
4042   _In_ PFNKSHANDLER Handler);
4043 
4044 _IRQL_requires_max_(PASSIVE_LEVEL)
4045 KSDDKAPI
4046 NTSTATUS
4047 NTAPI
4048 KsForwardAndCatchIrp(
4049   _In_ PDEVICE_OBJECT DeviceObject,
4050   _In_ PIRP Irp,
4051   _In_ PFILE_OBJECT FileObject,
4052   _In_ KSSTACK_USE StackUse);
4053 
4054 _IRQL_requires_max_(PASSIVE_LEVEL)
4055 KSDDKAPI
4056 NTSTATUS
4057 NTAPI
4058 KsForwardIrp(
4059   _In_ PIRP Irp,
4060   _In_ PFILE_OBJECT FileObject,
4061   _In_ BOOLEAN ReuseStackLocation);
4062 
4063 _IRQL_requires_max_(APC_LEVEL)
4064 KSDDKAPI
4065 VOID
4066 NTAPI
4067 KsFreeDeviceHeader(
4068   _In_ KSDEVICE_HEADER Header);
4069 
4070 _IRQL_requires_max_(APC_LEVEL)
4071 KSDDKAPI
4072 VOID
4073 NTAPI
4074 KsFreeObjectHeader(
4075   _In_ PVOID Header);
4076 
4077 KSDDKAPI
4078 NTSTATUS
4079 NTAPI
4080 KsGetChildCreateParameter(
4081   _In_ PIRP Irp,
4082   _Out_ PVOID *CreateParameter);
4083 
4084 _IRQL_requires_max_(DISPATCH_LEVEL)
4085 KSDDKAPI
4086 NTSTATUS
4087 NTAPI
4088 KsMoveIrpsOnCancelableQueue(
4089   _Inout_ PLIST_ENTRY SourceList,
4090   _In_ PKSPIN_LOCK SourceLock,
4091   _Inout_ PLIST_ENTRY DestinationList,
4092   _In_opt_ PKSPIN_LOCK DestinationLock,
4093   _In_ KSLIST_ENTRY_LOCATION ListLocation,
4094   _In_ PFNKSIRPLISTCALLBACK ListCallback,
4095   _In_ PVOID Context);
4096 
4097 _IRQL_requires_max_(PASSIVE_LEVEL)
4098 KSDDKAPI
4099 NTSTATUS
4100 NTAPI
4101 KsProbeStreamIrp(
4102   _Inout_ PIRP Irp,
4103   _In_ ULONG ProbeFlags,
4104   _In_ ULONG HeaderSize);
4105 
4106 _IRQL_requires_max_(PASSIVE_LEVEL)
4107 KSDDKAPI
4108 NTSTATUS
4109 NTAPI
4110 KsQueryInformationFile(
4111   _In_ PFILE_OBJECT FileObject,
4112   _Out_writes_bytes_(Length) PVOID FileInformation,
4113   _In_ ULONG Length,
4114   _In_ FILE_INFORMATION_CLASS FileInformationClass);
4115 
4116 _IRQL_requires_max_(PASSIVE_LEVEL)
4117 KSDDKAPI
4118 ACCESS_MASK
4119 NTAPI
4120 KsQueryObjectAccessMask(
4121   _In_ KSOBJECT_HEADER Header);
4122 
4123 _IRQL_requires_max_(PASSIVE_LEVEL)
4124 KSDDKAPI
4125 PKSOBJECT_CREATE_ITEM
4126 NTAPI
4127 KsQueryObjectCreateItem(
4128   _In_ KSOBJECT_HEADER Header);
4129 
4130 _IRQL_requires_max_(PASSIVE_LEVEL)
4131 KSDDKAPI
4132 NTSTATUS
4133 NTAPI
4134 KsReadFile(
4135   _In_ PFILE_OBJECT FileObject,
4136   _In_opt_ PKEVENT Event,
4137   _In_opt_ PVOID PortContext,
4138   _Out_ PIO_STATUS_BLOCK IoStatusBlock,
4139   _Out_writes_bytes_(Length) PVOID Buffer,
4140   _In_ ULONG Length,
4141   _In_opt_ ULONG Key,
4142   _In_ KPROCESSOR_MODE RequestorMode);
4143 
4144 _IRQL_requires_max_(DISPATCH_LEVEL)
4145 KSDDKAPI
4146 VOID
4147 NTAPI
4148 KsReleaseDevice(
4149   _In_ PKSDEVICE);
4150 
4151 _IRQL_requires_max_(DISPATCH_LEVEL)
4152 KSDDKAPI
4153 VOID
4154 NTAPI
4155 KsReleaseIrpOnCancelableQueue(
4156   _In_ PIRP Irp,
4157   _In_opt_ PDRIVER_CANCEL DriverCancel);
4158 
4159 _IRQL_requires_max_(DISPATCH_LEVEL)
4160 KSDDKAPI
4161 PIRP
4162 NTAPI
4163 KsRemoveIrpFromCancelableQueue(
4164   _Inout_ PLIST_ENTRY QueueHead,
4165   _In_ PKSPIN_LOCK SpinLock,
4166   _In_ KSLIST_ENTRY_LOCATION ListLocation,
4167   _In_ KSIRP_REMOVAL_OPERATION RemovalOperation);
4168 
4169 _IRQL_requires_max_(DISPATCH_LEVEL)
4170 KSDDKAPI
4171 VOID
4172 NTAPI
4173 KsRemoveSpecificIrpFromCancelableQueue(
4174   _In_ PIRP Irp);
4175 
4176 _IRQL_requires_max_(PASSIVE_LEVEL)
4177 KSDDKAPI
4178 NTSTATUS
4179 NTAPI
4180 KsSetInformationFile(
4181   _In_ PFILE_OBJECT FileObject,
4182   _In_reads_bytes_(Length) PVOID FileInformation,
4183   _In_ ULONG Length,
4184   _In_ FILE_INFORMATION_CLASS FileInformationClass);
4185 
4186 _IRQL_requires_max_(PASSIVE_LEVEL)
4187 KSDDKAPI
4188 NTSTATUS
4189 NTAPI
4190 KsSetMajorFunctionHandler(
4191   _In_ PDRIVER_OBJECT DriverObject,
4192   _In_ ULONG MajorFunction);
4193 
4194 _Check_return_
4195 _IRQL_requires_max_(PASSIVE_LEVEL)
4196 KSDDKAPI
4197 NTSTATUS
4198 NTAPI
4199 KsStreamIo(
4200   _In_ PFILE_OBJECT FileObject,
4201   _In_opt_ PKEVENT Event,
4202   _In_opt_ PVOID PortContext,
4203   _In_opt_ PIO_COMPLETION_ROUTINE CompletionRoutine,
4204   _In_opt_ PVOID CompletionContext,
4205   _In_opt_ KSCOMPLETION_INVOCATION CompletionInvocationFlags,
4206   _Out_ PIO_STATUS_BLOCK IoStatusBlock,
4207   _Inout_updates_bytes_(Length) PVOID StreamHeaders,
4208   _In_ ULONG Length,
4209   _In_ ULONG Flags,
4210   _In_ KPROCESSOR_MODE RequestorMode);
4211 
4212 _IRQL_requires_max_(DISPATCH_LEVEL)
4213 KSDDKAPI
4214 VOID
4215 NTAPI
4216 KsStreamPointerUnlock(
4217   _In_ PKSSTREAM_POINTER StreamPointer,
4218   _In_ BOOLEAN Eject);
4219 
4220 _IRQL_requires_max_(DISPATCH_LEVEL)
4221 KSDDKAPI
4222 NTSTATUS
4223 NTAPI
4224 KsStreamPointerAdvanceOffsets(
4225   _In_ PKSSTREAM_POINTER StreamPointer,
4226   _In_ ULONG             InUsed,
4227   _In_ ULONG             OutUsed,
4228   _In_ BOOLEAN           Eject);
4229 
4230 _Check_return_
4231 _IRQL_requires_max_(DISPATCH_LEVEL)
4232 KSDDKAPI
4233 NTSTATUS
4234 NTAPI
4235 KsStreamPointerAdvance(
4236   _In_ PKSSTREAM_POINTER StreamPointer);
4237 
4238 _IRQL_requires_max_(DISPATCH_LEVEL)
4239 KSDDKAPI
4240 VOID
4241 NTAPI
4242 KsStreamPointerAdvanceOffsetsAndUnlock(
4243 	_In_ PKSSTREAM_POINTER StreamPointer,
4244 	_In_ ULONG             InUsed,
4245 	_In_ ULONG             OutUsed,
4246 	_In_ BOOLEAN           Eject
4247 	);
4248 
4249 
4250 _IRQL_requires_max_(PASSIVE_LEVEL)
4251 KSDDKAPI
4252 NTSTATUS
4253 NTAPI
4254 KsWriteFile(
4255   _In_ PFILE_OBJECT FileObject,
4256   _In_opt_ PKEVENT Event,
4257   _In_opt_ PVOID PortContext,
4258   _Out_ PIO_STATUS_BLOCK IoStatusBlock,
4259   _In_reads_bytes_(Length) PVOID Buffer,
4260   _In_ ULONG Length,
4261   _In_opt_ ULONG Key,
4262   _In_ KPROCESSOR_MODE RequestorMode);
4263 
4264 KSDDKAPI
4265 NTSTATUS
4266 NTAPI
4267 KsDefaultForwardIrp(
4268   _In_ PDEVICE_OBJECT DeviceObject,
4269   _In_ PIRP Irp);
4270 
4271 /* ===============================================================
4272     Worker Management Functions
4273 */
4274 
4275 _IRQL_requires_max_(PASSIVE_LEVEL)
4276 KSDDKAPI
4277 NTSTATUS
4278 NTAPI
4279 KsRegisterWorker(
4280   _In_ WORK_QUEUE_TYPE WorkQueueType,
4281   _Out_ PKSWORKER* Worker);
4282 
4283 _IRQL_requires_max_(PASSIVE_LEVEL)
4284 KSDDKAPI
4285 VOID
4286 NTAPI
4287 KsUnregisterWorker(
4288   _In_ PKSWORKER Worker);
4289 
4290 _IRQL_requires_max_(PASSIVE_LEVEL)
4291 KSDDKAPI
4292 NTSTATUS
4293 NTAPI
4294 KsRegisterCountedWorker(
4295   _In_ WORK_QUEUE_TYPE WorkQueueType,
4296   _In_ PWORK_QUEUE_ITEM CountedWorkItem,
4297   _Out_ PKSWORKER *Worker);
4298 
4299 _IRQL_requires_max_(PASSIVE_LEVEL)
4300 KSDDKAPI
4301 ULONG
4302 NTAPI
4303 KsDecrementCountedWorker(
4304   _In_ PKSWORKER Worker);
4305 
4306 _IRQL_requires_max_(PASSIVE_LEVEL)
4307 KSDDKAPI
4308 ULONG
4309 NTAPI
4310 KsIncrementCountedWorker(
4311   _In_ PKSWORKER Worker);
4312 
4313 _IRQL_requires_max_(DISPATCH_LEVEL)
4314 KSDDKAPI
4315 NTSTATUS
4316 NTAPI
4317 KsQueueWorkItem(
4318   _In_ PKSWORKER Worker,
4319   _In_ PWORK_QUEUE_ITEM WorkItem);
4320 
4321 /* ===============================================================
4322     Resources / Images
4323 */
4324 
4325 _IRQL_requires_max_(PASSIVE_LEVEL)
4326 KSDDKAPI
4327 NTSTATUS
4328 NTAPI
4329 KsLoadResource(
4330   _In_ PVOID ImageBase,
4331   _In_ POOL_TYPE PoolType,
4332   _In_ ULONG_PTR ResourceName,
4333   _In_ ULONG ResourceType,
4334   _Outptr_result_bytebuffer_(*ResourceSize) PVOID *Resource,
4335   _Out_opt_ PULONG ResourceSize);
4336 
4337 _IRQL_requires_max_(PASSIVE_LEVEL)
4338 KSDDKAPI
4339 NTSTATUS
4340 NTAPI
4341 KsGetImageNameAndResourceId(
4342   _In_ HANDLE RegKey,
4343   _Out_ PUNICODE_STRING ImageName,
4344   _Out_ PULONG_PTR ResourceId,
4345   _Out_ PULONG ValueType);
4346 
4347 _IRQL_requires_max_(PASSIVE_LEVEL)
4348 KSDDKAPI
4349 NTSTATUS
4350 NTAPI
4351 KsMapModuleName(
4352   _In_ PDEVICE_OBJECT PhysicalDeviceObject,
4353   _In_ PUNICODE_STRING ModuleName,
4354   _Out_ PUNICODE_STRING ImageName,
4355   _Out_ PULONG_PTR ResourceId,
4356   _Out_ PULONG ValueType);
4357 
4358 /* ===============================================================
4359     Misc. Helper Functions
4360 */
4361 
4362 _IRQL_requires_max_(PASSIVE_LEVEL)
4363 KSDDKAPI
4364 PVOID
4365 NTAPI
4366 KsGetNextSibling(
4367   _In_ PVOID Object);
4368 
4369 _IRQL_requires_max_(PASSIVE_LEVEL)
4370 KSDDKAPI
4371 NTSTATUS
4372 NTAPI
4373 KsCacheMedium(
4374   _In_ PUNICODE_STRING SymbolicLink,
4375   _In_ PKSPIN_MEDIUM Medium,
4376   _In_ ULONG PinDirection);
4377 
4378 KSDDKAPI
4379 NTSTATUS
4380 NTAPI
4381 KsDefaultDispatchPnp(
4382   _In_ PDEVICE_OBJECT DeviceObject,
4383   _In_ PIRP Irp);
4384 
4385 _IRQL_requires_max_(PASSIVE_LEVEL)
4386 KSDDKAPI
4387 VOID
4388 NTAPI
4389 KsSetDevicePnpAndBaseObject(
4390   _In_ KSDEVICE_HEADER Header,
4391   _In_ PDEVICE_OBJECT PnpDeviceObject,
4392   _In_ PDEVICE_OBJECT BaseDevice);
4393 
4394 KSDDKAPI
4395 NTSTATUS
4396 NTAPI
4397 KsDefaultDispatchPower(
4398   _In_ PDEVICE_OBJECT DeviceObject,
4399   _In_ PIRP Irp);
4400 
4401 _IRQL_requires_max_(PASSIVE_LEVEL)
4402 KSDDKAPI
4403 VOID
4404 NTAPI
4405 KsSetPowerDispatch(
4406   _In_ KSOBJECT_HEADER Header,
4407   _In_opt_ PFNKSCONTEXT_DISPATCH PowerDispatch,
4408   _In_opt_ PVOID PowerContext);
4409 
4410 _IRQL_requires_max_(PASSIVE_LEVEL)
4411 KSDDKAPI
4412 NTSTATUS
4413 NTAPI
4414 KsReferenceBusObject(
4415   _In_ KSDEVICE_HEADER Header);
4416 
4417 _IRQL_requires_max_(PASSIVE_LEVEL)
4418 KSDDKAPI
4419 VOID
4420 NTAPI
4421 KsDereferenceBusObject(
4422   _In_ KSDEVICE_HEADER Header);
4423 
4424 _IRQL_requires_max_(PASSIVE_LEVEL)
4425 KSDDKAPI
4426 NTSTATUS
4427 NTAPI
4428 KsFreeObjectCreateItem(
4429   _In_ KSDEVICE_HEADER Header,
4430   _In_ PUNICODE_STRING CreateItem);
4431 
4432 _IRQL_requires_max_(PASSIVE_LEVEL)
4433 KSDDKAPI
4434 NTSTATUS
4435 NTAPI
4436 KsFreeObjectCreateItemsByContext(
4437   _In_ KSDEVICE_HEADER Header,
4438   _In_ PVOID Context);
4439 
4440 _IRQL_requires_max_(PASSIVE_LEVEL)
4441 KSDDKAPI
4442 VOID
4443 NTAPI
4444 KsNullDriverUnload(
4445   _In_ PDRIVER_OBJECT DriverObject);
4446 
4447 _IRQL_requires_max_(PASSIVE_LEVEL)
4448 KSDDKAPI
4449 PDEVICE_OBJECT
4450 NTAPI
4451 KsQueryDevicePnpObject(
4452   _In_ KSDEVICE_HEADER Header);
4453 
4454 _IRQL_requires_max_(PASSIVE_LEVEL)
4455 KSDDKAPI
4456 VOID
4457 NTAPI
4458 KsRecalculateStackDepth(
4459   _In_ KSDEVICE_HEADER Header,
4460   _In_ BOOLEAN ReuseStackLocation);
4461 
4462 _IRQL_requires_max_(PASSIVE_LEVEL)
4463 KSDDKAPI
4464 VOID
4465 NTAPI
4466 KsSetTargetDeviceObject(
4467   _In_ KSOBJECT_HEADER Header,
4468   _In_opt_ PDEVICE_OBJECT TargetDevice);
4469 
4470 _IRQL_requires_max_(PASSIVE_LEVEL)
4471 KSDDKAPI
4472 VOID
4473 NTAPI
4474 KsSetTargetState(
4475   _In_ KSOBJECT_HEADER Header,
4476   _In_ KSTARGET_STATE TargetState);
4477 
4478 _Must_inspect_result_
4479 _IRQL_requires_max_(PASSIVE_LEVEL)
4480 KSDDKAPI
4481 NTSTATUS
4482 NTAPI
4483 KsSynchronousIoControlDevice(
4484   _In_ PFILE_OBJECT FileObject,
4485   _In_ KPROCESSOR_MODE RequestorMode,
4486   _In_ ULONG IoControl,
4487   _In_reads_bytes_(InSize) PVOID InBuffer,
4488   _In_ ULONG InSize,
4489   _Out_writes_bytes_to_(OutSize, *BytesReturned) PVOID OutBuffer,
4490   _In_ ULONG OutSize,
4491   _Out_ PULONG BytesReturned);
4492 
4493 _IRQL_requires_max_(PASSIVE_LEVEL)
4494 KSDDKAPI
4495 PKSPIN
4496 NTAPI
4497 KsFilterGetFirstChildPin(
4498   _In_ PKSFILTER Filter,
4499   _In_ ULONG PinId);
4500 
4501 _IRQL_requires_max_(PASSIVE_LEVEL)
4502 KSDDKAPI
4503 PFILE_OBJECT
4504 NTAPI
4505 KsPinGetConnectedPinFileObject(
4506   _In_ PKSPIN Pin);
4507 
4508 #else /* _NTDDK_ */
4509 
4510 #if !defined( KS_NO_CREATE_FUNCTIONS )
4511 
4512 _IRQL_requires_max_(PASSIVE_LEVEL)
4513 KSDDKAPI
4514 DWORD
4515 WINAPI
4516 KsCreateAllocator(
4517   _In_ HANDLE ConnectionHandle,
4518   _In_ PKSALLOCATOR_FRAMING AllocatorFraming,
4519   _Out_ PHANDLE AllocatorHandle);
4520 
4521 _IRQL_requires_max_(PASSIVE_LEVEL)
4522 KSDDKAPI
4523 DWORD
4524 NTAPI
4525 KsCreateClock(
4526   _In_ HANDLE ConnectionHandle,
4527   _In_ PKSCLOCK_CREATE ClockCreate,
4528   _Out_ PHANDLE ClockHandle);
4529 
4530 _IRQL_requires_max_(PASSIVE_LEVEL)
4531 KSDDKAPI
4532 DWORD
4533 WINAPI
4534 KsCreatePin(
4535   _In_ HANDLE FilterHandle,
4536   _In_ PKSPIN_CONNECT Connect,
4537   _In_ ACCESS_MASK DesiredAccess,
4538   _Out_ PHANDLE ConnectionHandle);
4539 
4540 _IRQL_requires_max_(PASSIVE_LEVEL)
4541 KSDDKAPI
4542 DWORD
4543 WINAPI
4544 KsCreateTopologyNode(
4545   _In_ HANDLE ParentHandle,
4546   _In_ PKSNODE_CREATE NodeCreate,
4547   _In_ ACCESS_MASK DesiredAccess,
4548   _Out_ PHANDLE NodeHandle);
4549 
4550 #endif
4551 
4552 #endif /* _NTDDK_ */
4553 
4554 /* ===============================================================
4555     AVStream Functions (XP / DirectX 8)
4556     NOT IMPLEMENTED YET
4557     http://www.osronline.com/ddkx/stream/avstream_5q9f.htm
4558 */
4559 
4560 #if defined(_NTDDK_)
4561 
4562 _IRQL_requires_max_(PASSIVE_LEVEL)
4563 KSDDKAPI
4564 NTSTATUS
4565 NTAPI
4566 KsMergeAutomationTables(
4567   _Out_ PKSAUTOMATION_TABLE *AutomationTableAB,
4568   _In_opt_ PKSAUTOMATION_TABLE AutomationTableA,
4569   _In_opt_ PKSAUTOMATION_TABLE AutomationTableB,
4570   _In_opt_ KSOBJECT_BAG Bag);
4571 
4572 _Must_inspect_result_
4573 _IRQL_requires_max_(PASSIVE_LEVEL)
4574 KSDDKAPI
4575 NTSTATUS
4576 NTAPI
4577 KsInitializeDriver(
4578   _In_ PDRIVER_OBJECT DriverObject,
4579   _In_ PUNICODE_STRING RegistryPath,
4580   _In_opt_ const KSDEVICE_DESCRIPTOR  *Descriptor);
4581 
4582 typedef struct _KSFILTERFACTORY KSFILTERFACTORY, *PKSFILTERFACTORY; //FIXME
4583 
4584 _IRQL_requires_max_(PASSIVE_LEVEL)
4585 KSDDKAPI
4586 NTSTATUS
4587 NTAPI
4588 KsInitializeDevice (
4589   _In_ PDEVICE_OBJECT FunctionalDeviceObject,
4590   _In_ PDEVICE_OBJECT PhysicalDeviceObject,
4591   _In_ PDEVICE_OBJECT NextDeviceObject,
4592   _In_opt_ const KSDEVICE_DESCRIPTOR *Descriptor);
4593 
4594 _IRQL_requires_max_(PASSIVE_LEVEL)
4595 typedef void
4596 (NTAPI *PFNKSFILTERFACTORYPOWER)(
4597   _In_ PKSFILTERFACTORY FilterFactory,
4598   _In_ DEVICE_POWER_STATE State);
4599 
4600 _Must_inspect_result_
4601 _IRQL_requires_max_(PASSIVE_LEVEL)
4602 KSDDKAPI
4603 NTSTATUS
4604 NTAPI
4605 _KsEdit(
4606   _In_ KSOBJECT_BAG ObjectBag,
4607   _Inout_ PVOID *PointerToPointerToItem,
4608   _In_ ULONG NewSize,
4609   _In_ ULONG OldSize,
4610   _In_ ULONG Tag);
4611 
4612 _IRQL_requires_max_(PASSIVE_LEVEL)
4613 KSDDKAPI
4614 VOID
4615 NTAPI
4616 KsAcquireControl(
4617   _In_ PVOID Object);
4618 
4619 _IRQL_requires_max_(PASSIVE_LEVEL)
4620 KSDDKAPI
4621 VOID
4622 NTAPI
4623 KsAcquireDevice(
4624   _In_ PKSDEVICE Device);
4625 
4626 _IRQL_requires_max_(PASSIVE_LEVEL)
4627 KSDDKAPI
4628 NTSTATUS
4629 NTAPI
4630 KsAddDevice(
4631   _In_ PDRIVER_OBJECT DriverObject,
4632   _In_ PDEVICE_OBJECT PhysicalDeviceObject);
4633 
4634 _IRQL_requires_max_(PASSIVE_LEVEL)
4635 KSDDKAPI
4636 VOID
4637 NTAPI
4638 KsAddEvent(
4639   _In_ PVOID Object,
4640   _In_ PKSEVENT_ENTRY EventEntry);
4641 
4642 _Must_inspect_result_
4643 _IRQL_requires_max_(PASSIVE_LEVEL)
4644 KSDDKAPI
4645 NTSTATUS
4646 NTAPI
4647 KsAddItemToObjectBag(
4648   _In_ KSOBJECT_BAG ObjectBag,
4649   _In_ __drv_aliasesMem PVOID Item,
4650   _In_opt_ PFNKSFREE Free);
4651 
4652 _IRQL_requires_max_(PASSIVE_LEVEL)
4653 KSDDKAPI
4654 ULONG
4655 NTAPI
4656 KsRemoveItemFromObjectBag(
4657   _In_ KSOBJECT_BAG ObjectBag,
4658   _In_ PVOID Item,
4659   _In_ BOOLEAN Free);
4660 
4661 _IRQL_requires_max_(PASSIVE_LEVEL)
4662 KSDDKAPI
4663 NTSTATUS
4664 NTAPI
4665 KsAllocateObjectBag(
4666   _In_ PKSDEVICE Device,
4667   _Out_ KSOBJECT_BAG *ObjectBag);
4668 
4669 _IRQL_requires_max_(PASSIVE_LEVEL)
4670 KSDDKAPI
4671 VOID
4672 NTAPI
4673 KsFreeObjectBag(
4674   _In_ KSOBJECT_BAG ObjectBag);
4675 
4676 _IRQL_requires_max_(DISPATCH_LEVEL)
4677 KSDDKAPI
4678 VOID
4679 NTAPI
4680 KsCompletePendingRequest(
4681   _In_ PIRP Irp);
4682 
4683 _IRQL_requires_max_(PASSIVE_LEVEL)
4684 KSDDKAPI
4685 NTSTATUS
4686 NTAPI
4687 KsCopyObjectBagItems(
4688   _In_ KSOBJECT_BAG ObjectBagDestination,
4689   _In_ KSOBJECT_BAG ObjectBagSource);
4690 
4691 _IRQL_requires_max_(PASSIVE_LEVEL)
4692 KSDDKAPI
4693 NTSTATUS
4694 NTAPI
4695 KsCreateDevice(
4696   _In_ PDRIVER_OBJECT DriverObject,
4697   _In_ PDEVICE_OBJECT PhysicalDeviceObject,
4698   _In_opt_ const KSDEVICE_DESCRIPTOR *Descriptor,
4699   _In_ ULONG ExtensionSize,
4700   _Out_opt_ PKSDEVICE *Device);
4701 
4702 _Must_inspect_result_
4703 _IRQL_requires_max_(PASSIVE_LEVEL)
4704 KSDDKAPI
4705 NTSTATUS
4706 NTAPI
4707 KsCreateFilterFactory(
4708   _In_ PDEVICE_OBJECT DeviceObject,
4709   _In_ const KSFILTER_DESCRIPTOR *Descriptor,
4710   _In_opt_ PWSTR RefString,
4711   _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor,
4712   _In_ ULONG CreateItemFlags,
4713   _In_opt_ PFNKSFILTERFACTORYPOWER SleepCallback,
4714   _In_opt_ PFNKSFILTERFACTORYPOWER WakeCallback,
4715   _Out_opt_ PKSFILTERFACTORY *FilterFactory);
4716 
4717 _IRQL_requires_max_(PASSIVE_LEVEL)
4718 KSDDKAPI
4719 NTSTATUS
4720 NTAPI
4721 KsFilterFactorySetDeviceClassesState(
4722   _In_ PKSFILTERFACTORY FilterFactory,
4723   _In_ BOOLEAN NewState);
4724 
4725 _Must_inspect_result_
4726 _IRQL_requires_max_(PASSIVE_LEVEL)
4727 KSDDKAPI
4728 NTSTATUS
4729 NTAPI
4730 KsFilterFactoryUpdateCacheData(
4731   _In_ PKSFILTERFACTORY FilterFactory,
4732   _In_opt_ const KSFILTER_DESCRIPTOR *FilterDescriptor);
4733 
4734 _IRQL_requires_max_(DISPATCH_LEVEL)
4735 KSDDKAPI
4736 PKSPIN
4737 NTAPI
4738 KsGetPinFromIrp(
4739   _In_ PIRP Irp);
4740 
4741 _IRQL_requires_max_(DISPATCH_LEVEL)
4742 KSDDKAPI
4743 PKSFILTER
4744 NTAPI
4745 KsGetFilterFromIrp(
4746   _In_ PIRP Irp);
4747 
4748 _IRQL_requires_max_(PASSIVE_LEVEL)
4749 KSDDKAPI
4750 NTSTATUS
4751 NTAPI
4752 KsDefaultAddEventHandler(
4753   _In_ PIRP Irp,
4754   _In_ PKSEVENTDATA EventData,
4755   _Inout_ PKSEVENT_ENTRY EventEntry);
4756 
4757 _IRQL_requires_max_(PASSIVE_LEVEL)
4758 KSDDKAPI
4759 NTSTATUS
4760 NTAPI
4761 KsDispatchQuerySecurity(
4762   _In_ PDEVICE_OBJECT DeviceObject,
4763   _In_ PIRP Irp);
4764 
4765 _IRQL_requires_max_(PASSIVE_LEVEL)
4766 KSDDKAPI
4767 NTSTATUS
4768 NTAPI
4769 KsDispatchSetSecurity(
4770   _In_ PDEVICE_OBJECT DeviceObject,
4771   _In_ PIRP Irp);
4772 
4773 _IRQL_requires_max_(DISPATCH_LEVEL)
4774 KSDDKAPI
4775 VOID
4776 NTAPI
4777 KsPinAttemptProcessing(
4778     _In_ PKSPIN Pin,
4779     _In_ BOOLEAN Asynchronous);
4780 
4781 _IRQL_requires_max_(PASSIVE_LEVEL)
4782 KSDDKAPI
4783 VOID
4784 NTAPI
4785 KsPinAcquireProcessingMutex(
4786     _In_ PKSPIN Pin);
4787 
4788 _IRQL_requires_max_(PASSIVE_LEVEL)
4789 KSDDKAPI
4790 VOID
4791 NTAPI
4792 KsPinReleaseProcessingMutex(
4793     _In_ PKSPIN Pin);
4794 
4795 _IRQL_requires_max_(PASSIVE_LEVEL)
4796 KSDDKAPI
4797 PVOID
4798 NTAPI
4799 KsGetParent(
4800   _In_ PVOID Object);
4801 
_IRQL_requires_max_(PASSIVE_LEVEL)4802 _IRQL_requires_max_(PASSIVE_LEVEL)
4803 static
4804 __inline
4805 PKSFILTERFACTORY
4806 KsFilterGetParentFilterFactory(
4807     _In_ PKSFILTER Filter)
4808 {
4809     return (PKSFILTERFACTORY) KsGetParent((PVOID) Filter);
4810 }
4811 
_IRQL_requires_max_(PASSIVE_LEVEL)4812 _IRQL_requires_max_(PASSIVE_LEVEL)
4813 static
4814 __inline
4815 PKSDEVICE
4816 KsFilterFactoryGetParentDevice(
4817     _In_ PKSFILTERFACTORY FilterFactory)
4818 {
4819     return (PKSDEVICE) KsGetParent((PVOID) FilterFactory);
4820 }
4821 
4822 #define KsDeleteFilterFactory(FilterFactory) \
4823             KsFreeObjectCreateItemsByContext( \
4824             *(KSDEVICE_HEADER *)( \
4825             KsFilterFactoryGetParentDevice(FilterFactory)->FunctionalDeviceObject-> \
4826             DeviceExtension), \
4827             FilterFactory)
4828 
4829 _IRQL_requires_max_(PASSIVE_LEVEL)
4830 KSDDKAPI
4831 ULONG
4832 NTAPI
4833 KsDeviceGetBusData(
4834   _In_ PKSDEVICE Device,
4835   _In_ ULONG DataType,
4836   _In_reads_bytes_(Length) PVOID Buffer,
4837   _In_ ULONG Offset,
4838   _In_ ULONG Length);
4839 
4840 _IRQL_requires_max_(PASSIVE_LEVEL)
4841 KSDDKAPI
4842 PVOID
4843 NTAPI
4844 KsGetFirstChild(
4845   _In_ PVOID Object);
4846 
4847 _IRQL_requires_max_(PASSIVE_LEVEL)
4848 KSDDKAPI
4849 PKSFILTERFACTORY
4850 NTAPI
4851 KsDeviceGetFirstChildFilterFactory(
4852   _In_ PKSDEVICE Device);
4853 
4854 #if defined(_UNKNOWN_H_) || defined(__IUnknown_INTERFACE_DEFINED__)
4855 
4856 _IRQL_requires_max_(PASSIVE_LEVEL)
4857 KSDDKAPI
4858 PUNKNOWN
4859 NTAPI
4860 KsGetOuterUnknown(
4861   _In_ PVOID Object);
4862 
_IRQL_requires_max_(PASSIVE_LEVEL)4863 _IRQL_requires_max_(PASSIVE_LEVEL)
4864 static
4865 __inline
4866 PUNKNOWN
4867 KsDeviceGetOuterUnknown(
4868     _In_ PKSDEVICE Device)
4869 {
4870     return KsGetOuterUnknown((PVOID) Device);
4871 }
4872 
4873 _IRQL_requires_max_(PASSIVE_LEVEL)
4874 KSDDKAPI
4875 PUNKNOWN
4876 NTAPI
4877 KsDeviceRegisterAggregatedClientUnknown(
4878   _In_ PKSDEVICE Device,
4879   _In_ PUNKNOWN ClientUnknown);
4880 
4881 #endif
4882 
4883 #if defined(_UNKNOWN_H_) || defined(__IUnknown_INTERFACE_DEFINED__)
4884 
4885 typedef interface IKsReferenceClock* PIKSREFERENCECLOCK;
4886 
4887 #undef INTERFACE
4888 #define INTERFACE IKsReferenceClock
DECLARE_INTERFACE_(IKsReferenceClock,IUnknown)4889 DECLARE_INTERFACE_(IKsReferenceClock,IUnknown)
4890 {
4891     DEFINE_ABSTRACT_UNKNOWN() // For C
4892 
4893     STDMETHOD_(LONGLONG,GetTime)(THIS
4894         ) PURE;
4895     STDMETHOD_(LONGLONG,GetPhysicalTime)(THIS
4896         ) PURE;
4897     STDMETHOD_(LONGLONG,GetCorrelatedTime)(THIS_
4898         _Out_ PLONGLONG SystemTime
4899         ) PURE;
4900     STDMETHOD_(LONGLONG,GetCorrelatedPhysicalTime)(THIS_
4901         _Out_ PLONGLONG SystemTime
4902         ) PURE;
4903     STDMETHOD_(NTSTATUS, GetResolution)(THIS_
4904         _Out_ PKSRESOLUTION Resolution
4905         ) PURE;
4906     STDMETHOD_(NTSTATUS, GetState)(THIS_
4907         _Out_ PKSSTATE State
4908         ) PURE;
4909 };
4910 
4911 #undef INTERFACE
4912 #define INTERFACE IKsControl
4913 
4914 DEFINE_GUID(IID_IKsControl, 0x28F54685L, 0x06FD, 0x11D2, 0xB2, 0x7A, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96);
4915 
DECLARE_INTERFACE_(IKsControl,IUnknown)4916 DECLARE_INTERFACE_(IKsControl,IUnknown)
4917 {
4918     STDMETHOD_(NTSTATUS, QueryInterface)( THIS_
4919         REFIID InterfaceId,
4920         PVOID* Interface)PURE;
4921 
4922     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
4923 
4924     STDMETHOD_(ULONG, Release)(THIS) PURE;
4925 
4926     STDMETHOD_(NTSTATUS, KsProperty)(THIS_
4927         _In_reads_bytes_(PropertyLength) PKSPROPERTY Property,
4928         _In_ ULONG PropertyLength,
4929         _Inout_updates_bytes_(DataLength) PVOID PropertyData,
4930         _In_ ULONG DataLength,
4931         _Out_ ULONG *BytesReturned
4932         ) PURE;
4933     STDMETHOD_(NTSTATUS, KsMethod)(THIS_
4934         _In_reads_bytes_(MethodLength) PKSMETHOD Method,
4935         _In_ ULONG MethodLength,
4936         _Inout_updates_bytes_(DataLength) PVOID MethodData,
4937         _In_ ULONG DataLength,
4938         _Out_ ULONG *BytesReturned
4939         ) PURE;
4940     STDMETHOD_(NTSTATUS, KsEvent)(THIS_
4941         _In_reads_bytes_opt_(EventLength) PKSEVENT Event,
4942         _In_ ULONG EventLength,
4943         _Inout_updates_bytes_(DataLength) PVOID EventData,
4944         _In_ ULONG DataLength,
4945         _Out_ ULONG *BytesReturned
4946         ) PURE;
4947 };
4948 
4949 #undef INTERFACE
4950 typedef IKsControl* PIKSCONTROL;
4951 
4952 #endif
4953 
4954 _IRQL_requires_max_(PASSIVE_LEVEL)
4955 KSDDKAPI
4956 VOID
4957 NTAPI
4958 KsDeviceRegisterAdapterObject(
4959   _In_ PKSDEVICE Device,
4960   _In_ PADAPTER_OBJECT AdapterObject,
4961   _In_ ULONG MaxMappingByteCount,
4962   _In_ ULONG MappingTableStride);
4963 
4964 _IRQL_requires_max_(PASSIVE_LEVEL)
4965 KSDDKAPI
4966 ULONG
4967 NTAPI
4968 KsDeviceSetBusData(
4969   _In_ PKSDEVICE Device,
4970   _In_ ULONG DataType,
4971   _In_reads_bytes_(Length) PVOID Buffer,
4972   _In_ ULONG Offset,
4973   _In_ ULONG Length);
4974 
4975 _IRQL_requires_max_(PASSIVE_LEVEL)
4976 KSDDKAPI
4977 VOID
4978 NTAPI
4979 KsReleaseControl(
4980   _In_ PVOID Object);
4981 
4982 #define KsDiscard(object, pointer) \
4983     KsRemoveItemFromObjectBag(object->Bag, pointer, TRUE)
4984 
4985 #define KsFilterAcquireControl(Filter) \
4986     KsAcquireControl((PVOID) Filter);
4987 
4988 #define KsFilterReleaseControl(Filter) \
4989     KsReleaseControl((PVOID) Filter);
4990 
4991 #define KsFilterAddEvent(Filter, EventEntry) \
4992     KsAddEvent(Filter,EventEntry);
4993 
4994 _IRQL_requires_max_(PASSIVE_LEVEL)
4995 KSDDKAPI
4996 VOID
4997 NTAPI
4998 KsFilterAcquireProcessingMutex(
4999   _In_ PKSFILTER Filter);
5000 
5001 _IRQL_requires_max_(PASSIVE_LEVEL)
5002 KSDDKAPI
5003 NTSTATUS
5004 NTAPI
5005 KsFilterAddTopologyConnections(
5006   _In_ PKSFILTER Filter,
5007   _In_ ULONG NewConnectionsCount,
5008   _In_reads_(NewConnectionsCount) const KSTOPOLOGY_CONNECTION *const NewTopologyConnections);
5009 
5010 _IRQL_requires_max_(DISPATCH_LEVEL)
5011 KSDDKAPI
5012 VOID
5013 NTAPI
5014 KsFilterAttemptProcessing(
5015   _In_ PKSFILTER Filter,
5016   _In_ BOOLEAN Asynchronous);
5017 
5018 _IRQL_requires_max_(PASSIVE_LEVEL)
5019 KSDDKAPI
5020 NTSTATUS
5021 NTAPI
5022 KsFilterCreateNode(
5023   _In_ PKSFILTER Filter,
5024   _In_ const KSNODE_DESCRIPTOR *const NodeDescriptor,
5025   _Out_ PULONG NodeID);
5026 
5027 _IRQL_requires_max_(PASSIVE_LEVEL)
5028 KSDDKAPI
5029 NTSTATUS
5030 NTAPI
5031 KsFilterCreatePinFactory(
5032   _In_ PKSFILTER Filter,
5033   _In_ const KSPIN_DESCRIPTOR_EX *const PinDescriptor,
5034   _Out_ PULONG PinID);
5035 
5036 _IRQL_requires_max_(PASSIVE_LEVEL)
5037 KSDDKAPI
5038 PKSDEVICE
5039 NTAPI
5040 KsGetDevice(
5041   _In_ PVOID Object);
5042 
_IRQL_requires_max_(PASSIVE_LEVEL)5043 _IRQL_requires_max_(PASSIVE_LEVEL)
5044 static
5045 __inline
5046 PKSDEVICE
5047 KsFilterFactoryGetDevice(
5048   _In_ PKSFILTERFACTORY FilterFactory)
5049 {
5050     return KsGetDevice((PVOID)FilterFactory);
5051 }
5052 
5053 /* etc. */
5054 #endif /* avstream */
5055 
5056 #ifdef __cplusplus
5057 }
5058 #endif
5059 
5060 #endif /* _KS_ */
5061