Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

457 lines
13 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Module: fn.h
  4. //
  5. // Description: filter node classes
  6. //
  7. // Filter nodes represent the physical ks filter and along with PinInfo,
  8. // PinNodes, TopologyNodes, TopologyPins, TopologyConnections objects
  9. // represent the whole filter. These objects are built when sysaudio
  10. // is notified via audio class device interfaces arrivals.
  11. //
  12. // There is some info read from the registry for each filter. Various
  13. // defaults can be overriden:
  14. //
  15. // Device Parameters/Sysaudio/Disabled DWORD
  16. //
  17. // If !0, the filter isn't profiled or used in any graph.
  18. //
  19. // Device Parameters/Sysaudio/Capture DWORD
  20. //
  21. // If !0, puts the filters in the capture side of the graph. See
  22. // the FILTER_TYPE_CAPTURE define for the particular default of
  23. // a filter type.
  24. //
  25. // Device Parameters/Sysaudio/Render DWORD
  26. //
  27. // If !0, puts the filters in the render side of the graph. See
  28. // the FILTER_TYPE_RENDER define for the particular default of
  29. // a filter type.
  30. //
  31. // Device Parameters/Sysaudio/Order DWORD
  32. //
  33. // Overrides the default order in the graph. See the ORDER_XXXX
  34. // defines below for the default.
  35. //
  36. // Device Parameters/Sysaudio/Device STRING
  37. //
  38. // The device interface (in the KSCATEGORY_AUDIO class) of the
  39. // renderer and/or capturer device graph to put this filter. The
  40. // default is to put the filter in all device graphs.
  41. //
  42. //@@BEGIN_MSINTERNAL
  43. // Development Team:
  44. // Mike McLaughlin
  45. //
  46. // History: Date Author Comment
  47. //
  48. //@@END_MSINTERNAL
  49. //---------------------------------------------------------------------------
  50. //
  51. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  52. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  53. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  54. // PURPOSE.
  55. //
  56. // Copyright (c) 1996-1999 Microsoft Corporation. All Rights Reserved.
  57. //
  58. //---------------------------------------------------------------------------
  59. //---------------------------------------------------------------------------
  60. // Constants and Macros
  61. //---------------------------------------------------------------------------
  62. #define OVERHEAD_NONE 0
  63. #define OVERHEAD_LOWEST 1
  64. #define OVERHEAD_LOW 0x00001000
  65. #define OVERHEAD_HARDWARE 0x00010000
  66. #define OVERHEAD_MEDIUM 0x00100000
  67. #define OVERHEAD_SOFTWARE 0x01000000
  68. #define OVERHEAD_HIGH 0x10000000
  69. #define OVERHEAD_HIGHEST MAXULONG
  70. //---------------------------------------------------------------------------
  71. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  72. // MAKE SURE THAT NO FILTER ORDER IS ADDED BETWEEN GFX_FIRST & GFX_LAST
  73. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  74. #define ORDER_NONE 0
  75. #define ORDER_LOWEST 1
  76. #define ORDER_ENDPOINT 1
  77. #define ORDER_VIRTUAL 0x10000000
  78. #define ORDER_MIC_ARRAY_PROCESSOR 0x15000000
  79. #define ORDER_AEC 0x40000000
  80. #define ORDER_GFX 0x50000000
  81. #define ORDER_SPLITTER 0x20000000
  82. #define ORDER_MIXER 0xA0000000
  83. #define ORDER_SYNTHESIZER 0xB0000000
  84. #define ORDER_DATA_TRANSFORM 0xB0000000
  85. #define ORDER_DRM_DESCRAMBLE 0xB0000000
  86. #define ORDER_INTERFACE_TRANSFORM 0xC0000000
  87. #define ORDER_HIGHEST MAXULONG
  88. #define ORDER_CAPTURE_GFX_LAST (ORDER_SPLITTER-1)
  89. #define ORDER_CAPTURE_GFX_FIRST 0x10000001
  90. #define ORDER_RENDER_GFX_LAST ORDER_GFX
  91. #define ORDER_RENDER_GFX_FIRST (ORDER_AEC+1)
  92. //---------------------------------------------------------------------------
  93. #define FILTER_TYPE_AUDIO 0x00000001
  94. #define FILTER_TYPE_TOPOLOGY 0x00000002
  95. #define FILTER_TYPE_BRIDGE 0x00000004
  96. #define FILTER_TYPE_RENDERER 0x00000008
  97. #define FILTER_TYPE_CAPTURER 0x00000010
  98. #define FILTER_TYPE_MIXER 0x00000020
  99. #define FILTER_TYPE_GFX 0x00000040
  100. #define FILTER_TYPE_AEC 0x00000080
  101. #define FILTER_TYPE_DATA_TRANSFORM 0x00000100
  102. #define FILTER_TYPE_COMMUNICATION_TRANSFORM 0x00000200
  103. #define FILTER_TYPE_INTERFACE_TRANSFORM 0x00000400
  104. #define FILTER_TYPE_MEDIUM_TRANSFORM 0x00000800
  105. #define FILTER_TYPE_SPLITTER 0x00001000
  106. #define FILTER_TYPE_SYNTHESIZER 0x00002000
  107. #define FILTER_TYPE_DRM_DESCRAMBLE 0x00004000
  108. #define FILTER_TYPE_MIC_ARRAY_PROCESSOR 0x00008000
  109. #define FILTER_TYPE_VIRTUAL 0x00010000
  110. #define FILTER_TYPE_ENDPOINT (FILTER_TYPE_BRIDGE | \
  111. FILTER_TYPE_RENDERER | \
  112. FILTER_TYPE_CAPTURER)
  113. #define FILTER_TYPE_LOGICAL_FILTER (FILTER_TYPE_MIXER | \
  114. FILTER_TYPE_GFX | \
  115. FILTER_TYPE_AEC | \
  116. FILTER_TYPE_DATA_TRANSFORM | \
  117. FILTER_TYPE_INTERFACE_TRANSFORM | \
  118. FILTER_TYPE_SPLITTER | \
  119. FILTER_TYPE_SYNTHESIZER | \
  120. FILTER_TYPE_DRM_DESCRAMBLE | \
  121. FILTER_TYPE_MIC_ARRAY_PROCESSOR | \
  122. FILTER_TYPE_VIRTUAL)
  123. #define FILTER_TYPE_RENDER (FILTER_TYPE_INTERFACE_TRANSFORM | \
  124. FILTER_TYPE_GFX | \
  125. FILTER_TYPE_AEC | \
  126. FILTER_TYPE_MIXER | \
  127. FILTER_TYPE_SYNTHESIZER | \
  128. FILTER_TYPE_DRM_DESCRAMBLE | \
  129. FILTER_TYPE_VIRTUAL)
  130. #define FILTER_TYPE_CAPTURE (FILTER_TYPE_AEC | \
  131. FILTER_TYPE_MIC_ARRAY_PROCESSOR | \
  132. FILTER_TYPE_MIXER | \
  133. FILTER_TYPE_SPLITTER)
  134. #define FILTER_TYPE_PRE_MIXER (FILTER_TYPE_SYNTHESIZER | \
  135. FILTER_TYPE_DRM_DESCRAMBLE | \
  136. FILTER_TYPE_INTERFACE_TRANSFORM )
  137. #define FILTER_TYPE_NORMAL_TOPOLOGY (FILTER_TYPE_INTERFACE_TRANSFORM | \
  138. FILTER_TYPE_GFX | \
  139. FILTER_TYPE_ENDPOINT | \
  140. FILTER_TYPE_AEC | \
  141. FILTER_TYPE_MIC_ARRAY_PROCESSOR | \
  142. FILTER_TYPE_SYNTHESIZER | \
  143. FILTER_TYPE_DRM_DESCRAMBLE | \
  144. FILTER_TYPE_MIXER | \
  145. FILTER_TYPE_SPLITTER)
  146. #define FILTER_TYPE_MIXER_TOPOLOGY (FILTER_TYPE_VIRTUAL)
  147. #define FILTER_TYPE_NO_BYPASS (FILTER_TYPE_GFX)
  148. #define FILTER_TYPE_NOT_SELECT (FILTER_TYPE_AEC | \
  149. FILTER_TYPE_MIC_ARRAY_PROCESSOR)
  150. #define FILTER_TYPE_GLOBAL_SELECT (FILTER_TYPE_AEC)
  151. #define FILTER_TYPE_DUP_FOR_CAPTURE (FILTER_TYPE_MIXER)
  152. //---------------------------------------------------------------------------
  153. #define FN_FLAGS_RENDER 0x00000001
  154. #define FN_FLAGS_NO_RENDER 0x00000002
  155. #define FN_FLAGS_CAPTURE 0x00000004
  156. #define FN_FLAGS_NO_CAPTURE 0x00000008
  157. //---------------------------------------------------------------------------
  158. // Class List Definitions
  159. //---------------------------------------------------------------------------
  160. typedef ListDoubleDestroy<CFilterNode> LIST_FILTER_NODE, *PLIST_FILTER_NODE;
  161. //---------------------------------------------------------------------------
  162. typedef ListData<CFilterNode> LIST_DATA_FILTER_NODE, *PLIST_DATA_FILTER_NODE;
  163. //---------------------------------------------------------------------------
  164. typedef ListDataAssertLess<WCHAR> LIST_WSTR;
  165. //---------------------------------------------------------------------------
  166. // Classes
  167. //---------------------------------------------------------------------------
  168. typedef class CFilterNode : public CListDoubleItem
  169. {
  170. public:
  171. CFilterNode(
  172. ULONG fulType
  173. );
  174. ~CFilterNode(
  175. );
  176. NTSTATUS
  177. Create(
  178. PWSTR pwstrDeviceInterface
  179. );
  180. NTSTATUS
  181. ProfileFilter(
  182. PFILE_OBJECT pFileObject
  183. );
  184. NTSTATUS
  185. DuplicateForCapture(
  186. );
  187. ENUMFUNC
  188. Destroy(
  189. )
  190. {
  191. Assert(this);
  192. delete this;
  193. return(STATUS_CONTINUE);
  194. };
  195. NTSTATUS
  196. OpenDevice(
  197. OUT PHANDLE pHandle
  198. )
  199. {
  200. ASSERT(pwstrDeviceInterface != NULL);
  201. return(::OpenDevice(pwstrDeviceInterface, pHandle));
  202. };
  203. BOOL
  204. IsDeviceInterfaceMatch(
  205. PDEVICE_NODE pDeviceNode
  206. );
  207. NTSTATUS
  208. AddDeviceInterfaceMatch(
  209. PWSTR pwstr
  210. )
  211. {
  212. return(lstwstrDeviceInterfaceMatch.AddList(pwstr));
  213. };
  214. ULONG
  215. GetFlags(
  216. )
  217. {
  218. return(ulFlags);
  219. };
  220. VOID
  221. SetRenderOnly(
  222. )
  223. {
  224. PLOGICAL_FILTER_NODE pLogicalFilterNode;
  225. FOR_EACH_LIST_ITEM(&lstLogicalFilterNode, pLogicalFilterNode) {
  226. pLogicalFilterNode->SetRenderOnly();
  227. } END_EACH_LIST_ITEM
  228. };
  229. VOID
  230. SetCaptureOnly(
  231. )
  232. {
  233. PLOGICAL_FILTER_NODE pLogicalFilterNode;
  234. FOR_EACH_LIST_ITEM(&lstLogicalFilterNode, pLogicalFilterNode) {
  235. pLogicalFilterNode->SetCaptureOnly();
  236. } END_EACH_LIST_ITEM
  237. };
  238. ULONG
  239. GetOrder(
  240. )
  241. {
  242. return(ulOrder);
  243. };
  244. VOID
  245. SetOrder(
  246. ULONG ulOrder
  247. )
  248. {
  249. PLOGICAL_FILTER_NODE pLogicalFilterNode;
  250. FOR_EACH_LIST_ITEM(&lstLogicalFilterNode, pLogicalFilterNode) {
  251. pLogicalFilterNode->SetOrder(ulOrder);
  252. } END_EACH_LIST_ITEM
  253. this->ulOrder = ulOrder;
  254. };
  255. ULONG
  256. GetType(
  257. )
  258. {
  259. return(fulType);
  260. };
  261. VOID
  262. SetType(
  263. ULONG fulType
  264. );
  265. VOID
  266. SetRenderCaptureFlags(
  267. ULONG fulFlags
  268. )
  269. {
  270. if (fulFlags == GFX_DEVICETYPE_RENDER) {
  271. ulFlags |= FN_FLAGS_RENDER | FN_FLAGS_NO_CAPTURE;
  272. } else if (fulFlags == GFX_DEVICETYPE_CAPTURE) {
  273. ulFlags |= FN_FLAGS_CAPTURE | FN_FLAGS_NO_RENDER;
  274. }
  275. else {
  276. Trap();
  277. }
  278. }
  279. PFILE_OBJECT
  280. GetFileObject(
  281. )
  282. {
  283. return(pFileObject);
  284. }
  285. VOID
  286. SetFileDetails(
  287. HANDLE Handle,
  288. PFILE_OBJECT pFileObject,
  289. PEPROCESS pProcess
  290. )
  291. {
  292. this->hFileHandle = Handle;
  293. this->pFileObject = pFileObject;
  294. this->pProcess = pProcess;
  295. }
  296. void
  297. ClearFileDetails(
  298. )
  299. {
  300. ::ObDereferenceObject(this->pFileObject);
  301. this->pFileObject = NULL;
  302. this->hFileHandle = 0;
  303. this->pProcess = NULL;
  304. }
  305. BOOL
  306. CFilterNode::DoesGfxMatch(
  307. HANDLE hGfx,
  308. PWSTR pwstrDeviceName,
  309. ULONG GfxOrder
  310. );
  311. NTSTATUS
  312. CreatePin(
  313. PKSPIN_CONNECT pPinConnect,
  314. ACCESS_MASK Access,
  315. PHANDLE pHandle
  316. );
  317. PKSCOMPONENTID
  318. GetComponentId(
  319. )
  320. {
  321. return(ComponentId);
  322. };
  323. PWSTR
  324. GetFriendlyName(
  325. )
  326. {
  327. return(pwstrFriendlyName);
  328. };
  329. VOID
  330. SetFriendlyName(
  331. PWSTR pwstr
  332. )
  333. {
  334. pwstrFriendlyName = pwstr;
  335. };
  336. PWSTR
  337. GetDeviceInterface(
  338. )
  339. {
  340. return(pwstrDeviceInterface);
  341. };
  342. #ifdef DEBUG
  343. PSZ DumpName()
  344. {
  345. return(DbgUnicode2Sz(pwstrFriendlyName));
  346. };
  347. #endif
  348. PDEVICE_NODE pDeviceNode;
  349. LIST_PIN_INFO lstPinInfo;
  350. LIST_TOPOLOGY_NODE lstTopologyNode;
  351. LIST_DESTROY_TOPOLOGY_CONNECTION lstTopologyConnection;
  352. LIST_DESTROY_LOGICAL_FILTER_NODE lstLogicalFilterNode;
  353. LIST_DATA_FILTER_NODE lstConnectedFilterNode;
  354. CLIST_DATA lstFreeMem; // list of blocks to free
  355. private:
  356. LIST_WSTR lstwstrDeviceInterfaceMatch;
  357. PWSTR pwstrDeviceInterface;
  358. PWSTR pwstrFriendlyName;
  359. ULONG ulFlags;
  360. ULONG fulType;
  361. ULONG ulOrder;
  362. PKSCOMPONENTID ComponentId;
  363. PFILE_OBJECT pFileObject;
  364. HANDLE hFileHandle;
  365. PEPROCESS pProcess;
  366. public:
  367. ULONG cPins;
  368. DefineSignature(0x20204E46); // FN
  369. } FILTER_NODE, *PFILTER_NODE;
  370. //---------------------------------------------------------------------------
  371. // Inline functions
  372. //---------------------------------------------------------------------------
  373. inline ULONG
  374. CLogicalFilterNode::GetType(
  375. )
  376. {
  377. return(pFilterNode->GetType());
  378. }
  379. //---------------------------------------------------------------------------
  380. // Globals
  381. //---------------------------------------------------------------------------
  382. extern PLIST_FILTER_NODE gplstFilterNode;
  383. //---------------------------------------------------------------------------
  384. // Local prototypes
  385. //---------------------------------------------------------------------------
  386. NTSTATUS
  387. InitializeFilterNode(
  388. );
  389. VOID
  390. UninitializeFilterNode(
  391. );
  392. //---------------------------------------------------------------------------