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.

637 lines
16 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2000-2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: kshlp.cpp
  6. * Content: WDM/CSA helper functions.
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 05/16/2000 jstokes Created.
  11. * 03/09/2001 duganp Fixed return code mistranslation.
  12. *
  13. ***************************************************************************/
  14. #include <windows.h>
  15. #include <ks.h>
  16. #include <ksmedia.h>
  17. #include "ksdbgprop.h"
  18. #include "kshlp.h"
  19. #include <devioctl.h>
  20. #include "runtime.h"
  21. /***************************************************************************
  22. *
  23. * SyncIoctl
  24. *
  25. ***************************************************************************/
  26. static BOOL SyncIoctl
  27. (
  28. IN HANDLE handle,
  29. IN ULONG ulIoctl,
  30. IN PVOID pvInBuffer OPTIONAL,
  31. IN ULONG ulInSize,
  32. OUT PVOID pvOutBuffer OPTIONAL,
  33. IN ULONG ulOutSize,
  34. OUT PULONG pulBytesReturned
  35. )
  36. {
  37. OVERLAPPED overlapped;
  38. memset(&overlapped, 0, sizeof overlapped);
  39. overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  40. if (!overlapped.hEvent)
  41. {
  42. return FALSE;
  43. }
  44. BOOL fResult = DeviceIoControl(handle,
  45. ulIoctl,
  46. pvInBuffer,
  47. ulInSize,
  48. pvOutBuffer,
  49. ulOutSize,
  50. pulBytesReturned,
  51. &overlapped);
  52. DWORD dwError = GetLastError();
  53. if (!fResult && dwError == ERROR_IO_PENDING)
  54. {
  55. if (WaitForSingleObject(overlapped.hEvent, INFINITE) != WAIT_FAILED)
  56. {
  57. fResult = TRUE;
  58. }
  59. }
  60. else if (!fResult)
  61. {
  62. if ( (ulIoctl == IOCTL_KS_PROPERTY)
  63. && (ulOutSize == 0)
  64. && (dwError == ERROR_MORE_DATA)
  65. )
  66. {
  67. fResult = TRUE;
  68. }
  69. else
  70. {
  71. *pulBytesReturned = 0;
  72. }
  73. }
  74. CloseHandle(overlapped.hEvent);
  75. return fResult;
  76. }
  77. /***************************************************************************
  78. *
  79. * KsGetProperty
  80. *
  81. * Description:
  82. * Retrieves a particular property on a device.
  83. *
  84. * Arguments:
  85. * HANDLE [in]: device handle.
  86. * REFGUID [in]: property set id.
  87. * DWORD [in]: property id.
  88. * LPVOID [out]: receives property data.
  89. * DWORD [in]: size of above buffer.
  90. *
  91. * Returns:
  92. * HRESULT: DirectSound/COM result code.
  93. *
  94. ***************************************************************************/
  95. #undef DPF_FNAME
  96. #define DPF_FNAME "KsGetProperty"
  97. HRESULT
  98. KsGetProperty
  99. (
  100. HANDLE hDevice,
  101. REFGUID guidPropertySet,
  102. ULONG ulPropertyId,
  103. LPVOID pvData,
  104. ULONG cbData,
  105. PULONG pcbDataReturned
  106. )
  107. {
  108. KSPROPERTY Property;
  109. HRESULT hr;
  110. Property.Set = guidPropertySet;
  111. Property.Id = ulPropertyId;
  112. Property.Flags = KSPROPERTY_TYPE_GET;
  113. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &Property, sizeof Property, pvData, cbData, pcbDataReturned))
  114. {
  115. hr = cbData ? S_OK : S_FALSE;
  116. }
  117. else
  118. {
  119. DWORD dwError = GetLastError();
  120. hr = HRESULT_FROM_WIN32(dwError);
  121. }
  122. return hr;
  123. }
  124. /***************************************************************************
  125. *
  126. * KsSetProperty
  127. *
  128. * Description:
  129. * Sets a particular property on a device.
  130. *
  131. * Arguments:
  132. * HANDLE [in]: device handle.
  133. * REFGUID [in]: property set id.
  134. * DWORD [in]: property id.
  135. * LPVOID [in]: property data.
  136. * DWORD [in]: size of above buffer.
  137. *
  138. * Returns:
  139. * HRESULT: DirectSound/COM result code.
  140. *
  141. ***************************************************************************/
  142. #undef DPF_FNAME
  143. #define DPF_FNAME "KsSetProperty"
  144. HRESULT
  145. KsSetProperty
  146. (
  147. HANDLE hDevice,
  148. REFGUID guidPropertySet,
  149. ULONG ulPropertyId,
  150. LPVOID pvData,
  151. ULONG cbData
  152. )
  153. {
  154. KSPROPERTY Property;
  155. HRESULT hr;
  156. ULONG ulBytesReturned;
  157. Property.Set = guidPropertySet;
  158. Property.Id = ulPropertyId;
  159. Property.Flags = KSPROPERTY_TYPE_SET;
  160. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &Property, sizeof Property, pvData, cbData, &ulBytesReturned))
  161. {
  162. hr = cbData ? S_OK : S_FALSE;
  163. }
  164. else
  165. {
  166. DWORD dwError = GetLastError();
  167. hr = HRESULT_FROM_WIN32(dwError);
  168. }
  169. return hr;
  170. }
  171. /***************************************************************************
  172. *
  173. * KsGetPinProperty
  174. *
  175. * Description:
  176. * Retrieves a particular property on a pin.
  177. *
  178. * Arguments:
  179. * HANDLE [in]: device handle.
  180. * DWORD [in]: property id.
  181. * DWORD [in]: pin id.
  182. * LPVOID [out]: receives property data.
  183. * DWORD [in]: size of above buffer.
  184. *
  185. * Returns:
  186. * HRESULT: DirectSound/COM result code.
  187. *
  188. ***************************************************************************/
  189. #undef DPF_FNAME
  190. #define DPF_FNAME "KsGetPinProperty"
  191. HRESULT
  192. KsGetPinProperty
  193. (
  194. HANDLE hDevice,
  195. ULONG ulPropertyId,
  196. ULONG ulPinId,
  197. LPVOID pvData,
  198. ULONG cbData,
  199. PULONG pcbDataReturned
  200. )
  201. {
  202. KSP_PIN Pin;
  203. HRESULT hr;
  204. Pin.Property.Set = KSPROPSETID_Pin;
  205. Pin.Property.Id = ulPropertyId;
  206. Pin.Property.Flags = KSPROPERTY_TYPE_GET;
  207. Pin.PinId = ulPinId;
  208. Pin.Reserved = 0;
  209. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &Pin, sizeof Pin, pvData, cbData, pcbDataReturned))
  210. {
  211. hr = cbData ? S_OK : S_FALSE;
  212. }
  213. else
  214. {
  215. DWORD dwError = GetLastError();
  216. hr = HRESULT_FROM_WIN32(dwError);
  217. }
  218. return hr;
  219. }
  220. /***************************************************************************
  221. *
  222. * KsSetPinProperty
  223. *
  224. * Description:
  225. * Sets a particular property on a pin.
  226. *
  227. * Arguments:
  228. * HANDLE [in]: device handle.
  229. * DWORD [in]: property id.
  230. * DWORD [in]: pin id.
  231. * LPVOID [out]: property data.
  232. * DWORD [in]: size of above buffer.
  233. *
  234. * Returns:
  235. * HRESULT: DirectSound/COM result code.
  236. *
  237. ***************************************************************************/
  238. #undef DPF_FNAME
  239. #define DPF_FNAME "KsSetPinProperty"
  240. HRESULT
  241. KsSetPinProperty
  242. (
  243. HANDLE hDevice,
  244. ULONG ulPropertyId,
  245. ULONG ulPinId,
  246. LPVOID pvData,
  247. ULONG cbData
  248. )
  249. {
  250. KSP_PIN Pin;
  251. HRESULT hr;
  252. ULONG ulBytesReturned;
  253. Pin.Property.Set = KSPROPSETID_Pin;
  254. Pin.Property.Id = ulPropertyId;
  255. Pin.Property.Flags = KSPROPERTY_TYPE_SET;
  256. Pin.PinId = ulPinId;
  257. Pin.Reserved = 0;
  258. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &Pin, sizeof Pin, pvData, cbData, &ulBytesReturned))
  259. {
  260. hr = cbData ? S_OK : S_FALSE;
  261. }
  262. else
  263. {
  264. DWORD dwError = GetLastError();
  265. hr = HRESULT_FROM_WIN32(dwError);
  266. }
  267. return hr;
  268. }
  269. /***************************************************************************
  270. *
  271. * KsGetNodeProperty
  272. *
  273. * Description:
  274. * Retrieves a particular property on a topology node.
  275. *
  276. * Arguments:
  277. * HANDLE [in]: device handle.
  278. * REFGUID [in]: property set id.
  279. * ULONG [in]: property id.
  280. * ULONG [in]: node id.
  281. * ULONG [in]: flags.
  282. * LPVOID [out]: receives property data.
  283. * DWORD [in]: size of above buffer.
  284. *
  285. * Returns:
  286. * HRESULT: DirectSound/COM result code.
  287. *
  288. ***************************************************************************/
  289. #undef DPF_FNAME
  290. #define DPF_FNAME "KsGetNodeProperty"
  291. HRESULT
  292. KsGetNodeProperty
  293. (
  294. HANDLE hDevice,
  295. REFGUID guidPropertySet,
  296. ULONG ulPropertyId,
  297. ULONG ulNodeId,
  298. LPVOID pvData,
  299. ULONG cbData,
  300. PULONG pcbDataReturned
  301. )
  302. {
  303. KSNODEPROPERTY NodeProperty;
  304. HRESULT hr;
  305. NodeProperty.Property.Set = guidPropertySet;
  306. NodeProperty.Property.Id = ulPropertyId;
  307. NodeProperty.Property.Flags = KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_TOPOLOGY;
  308. NodeProperty.NodeId = ulNodeId;
  309. NodeProperty.Reserved = 0;
  310. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &NodeProperty, sizeof(NodeProperty), pvData, cbData, pcbDataReturned))
  311. {
  312. hr = cbData ? S_OK : S_FALSE;
  313. }
  314. else
  315. {
  316. DWORD dwError = GetLastError();
  317. hr = HRESULT_FROM_WIN32(dwError);
  318. }
  319. return hr;
  320. }
  321. /***************************************************************************
  322. *
  323. * KsSetNodeProperty
  324. *
  325. * Description:
  326. * Sets a particular property on a topology node.
  327. *
  328. * Arguments:
  329. * HANDLE [in]: device handle.
  330. * REFGUID [in]: property set id.
  331. * ULONG [in]: property id.
  332. * ULONG [in]: node id.
  333. * ULONG [in]: flags.
  334. * LPVOID [in]: property data.
  335. * DWORD [in]: size of above buffer.
  336. *
  337. * Returns:
  338. * HRESULT: DirectSound/COM result code.
  339. *
  340. ***************************************************************************/
  341. #undef DPF_FNAME
  342. #define DPF_FNAME "KsSetNodeProperty"
  343. HRESULT
  344. KsSetNodeProperty
  345. (
  346. HANDLE hDevice,
  347. REFGUID guidPropertySet,
  348. ULONG ulPropertyId,
  349. ULONG ulNodeId,
  350. LPVOID pvData,
  351. ULONG cbData
  352. )
  353. {
  354. KSNODEPROPERTY NodeProperty;
  355. HRESULT hr;
  356. ULONG ulBytesReturned;
  357. NodeProperty.Property.Set = guidPropertySet;
  358. NodeProperty.Property.Id = ulPropertyId;
  359. NodeProperty.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
  360. NodeProperty.NodeId = ulNodeId;
  361. NodeProperty.Reserved = 0;
  362. if (SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &NodeProperty, sizeof NodeProperty, pvData, cbData, &ulBytesReturned))
  363. {
  364. hr = cbData ? S_OK : S_FALSE;
  365. }
  366. else
  367. {
  368. DWORD dwError = GetLastError();
  369. hr = HRESULT_FROM_WIN32(dwError);
  370. }
  371. return hr;
  372. }
  373. /***************************************************************************
  374. *
  375. * KsGetDebugNodeProperty
  376. *
  377. * Description:
  378. * Retrieves a particular property on a topology node.
  379. *
  380. * Arguments:
  381. * HANDLE [in]: device handle.
  382. * REFGUID [in]: property set id.
  383. * ULONG [in]: property id.
  384. * ULONG [in]: node id.
  385. * ULONG [in]: flags.
  386. * LPVOID [out]: receives property data.
  387. * DWORD [in]: size of above buffer.
  388. *
  389. * Returns:
  390. * HRESULT: DirectSound/COM result code.
  391. *
  392. ***************************************************************************/
  393. /*
  394. #undef DPF_FNAME
  395. #define DPF_FNAME "KsGetDebugNodeProperty"
  396. HRESULT
  397. KsGetDebugNodeProperty
  398. (
  399. HANDLE hDevice,
  400. REFGUID guidPropertySet,
  401. ULONG ulPropertyId,
  402. ULONG ulNodeId,
  403. ULONG ulDebugId,
  404. LPVOID pvData,
  405. ULONG cbData,
  406. PULONG pcbDataReturned
  407. )
  408. {
  409. KSDEBUGNODEPROPERTY DebugNodeProperty;
  410. HRESULT hr;
  411. DebugNodeProperty.NodeProperty.Property.Set = guidPropertySet;
  412. DebugNodeProperty.NodeProperty.Property.Id = ulPropertyId;
  413. DebugNodeProperty.NodeProperty.Property.Flags = KSPROPERTY_TYPE_GET | KSPROPERTY_TYPE_TOPOLOGY;
  414. DebugNodeProperty.NodeProperty.NodeId = ulNodeId;
  415. DebugNodeProperty.NodeProperty.Reserved = 0;
  416. DebugNodeProperty.DebugId = ulDebugId;
  417. DebugNodeProperty.Reserved = 0;
  418. hr = SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &DebugNodeProperty, sizeof DebugNodeProperty, pvData, cbData, pcbDataReturned);
  419. return hr;
  420. }
  421. */
  422. /***************************************************************************
  423. *
  424. * KsSetDebugNodeProperty
  425. *
  426. * Description:
  427. * Sets a particular property on a topology node.
  428. *
  429. * Arguments:
  430. * HANDLE [in]: device handle.
  431. * REFGUID [in]: property set id.
  432. * ULONG [in]: property id.
  433. * ULONG [in]: node id.
  434. * ULONG [in]: flags.
  435. * LPVOID [in]: property data.
  436. * DWORD [in]: size of above buffer.
  437. *
  438. * Returns:
  439. * HRESULT: DirectSound/COM result code.
  440. *
  441. ***************************************************************************/
  442. /*
  443. #undef DPF_FNAME
  444. #define DPF_FNAME "KsSetDebugNodeProperty"
  445. HRESULT
  446. KsSetDebugNodeProperty
  447. (
  448. HANDLE hDevice,
  449. REFGUID guidPropertySet,
  450. ULONG ulPropertyId,
  451. ULONG ulNodeId,
  452. ULONG ulDebugId,
  453. LPVOID pvData,
  454. ULONG cbData
  455. )
  456. {
  457. KSDEBUGNODEPROPERTY DebugNodeProperty;
  458. HRESULT hr;
  459. ULONG ulBytesReturned;
  460. DebugNodeProperty.NodeProperty.Property.Set = guidPropertySet;
  461. DebugNodeProperty.NodeProperty.Property.Id = ulPropertyId;
  462. DebugNodeProperty.NodeProperty.Property.Flags = KSPROPERTY_TYPE_SET | KSPROPERTY_TYPE_TOPOLOGY;
  463. DebugNodeProperty.NodeProperty.NodeId = ulNodeId;
  464. DebugNodeProperty.NodeProperty.Reserved = 0;
  465. DebugNodeProperty.DebugId = ulDebugId;
  466. DebugNodeProperty.Reserved = 0;
  467. hr = SyncIoctl(hDevice, IOCTL_KS_PROPERTY, &DebugNodeProperty, sizeof DebugNodeProperty, pvData, cbData, &ulBytesReturned);
  468. return hr;
  469. }
  470. */
  471. /***************************************************************************
  472. *
  473. * KsSetTopologyNodeEnable
  474. *
  475. * Description:
  476. * Enables or disables a topology node.
  477. *
  478. * Arguments:
  479. * HANDLE [in]: device handle.
  480. * ULONG [in]: node id.
  481. * BOOL [in]: enable value.
  482. *
  483. * Returns:
  484. * HRESULT: DirectSound/COM result code.
  485. *
  486. ***************************************************************************/
  487. #undef DPF_FNAME
  488. #define DPF_FNAME "KsSetTopologyNodeEnable"
  489. HRESULT
  490. KsSetTopologyNodeEnable
  491. (
  492. HANDLE hDevice,
  493. ULONG ulNodeId,
  494. BOOL fEnable
  495. )
  496. {
  497. return KsSetNodeProperty(hDevice, KSPROPSETID_TopologyNode, KSPROPERTY_TOPOLOGYNODE_ENABLE, ulNodeId, &fEnable, sizeof fEnable);
  498. }
  499. /***************************************************************************
  500. *
  501. * KsGetTopologyNodeEnable
  502. *
  503. * Description:
  504. * Gets the value for the topology node's enable flag.
  505. *
  506. * Arguments:
  507. * HANDLE [in]: pin id.
  508. * ULONG [in]: node id.
  509. * PBOOL [out]: receives enable flag.
  510. *
  511. * Returns:
  512. * HRESULT: DirectSound/COM result code.
  513. *
  514. ***************************************************************************/
  515. #undef DPF_FNAME
  516. #define DPF_FNAME "KsGetTopologyNodeEnable"
  517. HRESULT
  518. KsGetTopologyNodeEnable
  519. (
  520. HANDLE hDevice,
  521. ULONG ulNodeId,
  522. PBOOL pEnable
  523. )
  524. {
  525. return KsGetNodeProperty(hDevice, KSPROPSETID_TopologyNode, KSPROPERTY_TOPOLOGYNODE_ENABLE, ulNodeId, pEnable, sizeof BOOL);
  526. }
  527. /***************************************************************************
  528. *
  529. * KsTopologyNodeReset
  530. *
  531. * Description:
  532. * Resets a topology node.
  533. *
  534. * Arguments:
  535. * HANDLE [in]: device handle.
  536. * ULONG [in]: node id.
  537. * BOOL [in]: enable value.
  538. *
  539. * Returns:
  540. * HRESULT: DirectSound/COM result code.
  541. *
  542. ***************************************************************************/
  543. #undef DPF_FNAME
  544. #define DPF_FNAME "KsTopologyNodeReset"
  545. HRESULT
  546. KsTopologyNodeReset
  547. (
  548. HANDLE hDevice,
  549. ULONG ulNodeId,
  550. BOOL fReset
  551. )
  552. {
  553. return KsSetNodeProperty(hDevice, KSPROPSETID_TopologyNode, KSPROPERTY_TOPOLOGYNODE_RESET, ulNodeId, &fReset, sizeof fReset);
  554. }