Source code of Windows XP (NT5)
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.

254 lines
8.0 KiB

  1. #include <windows.h>
  2. #include <objbase.h>
  3. #include <devioctl.h>
  4. #include <ks.h>
  5. #include <ksmedia.h>
  6. #include "debug.h"
  7. #include "reg.h"
  8. #include "ksi.h"
  9. extern "C" HANDLE hHeap;
  10. const int StrLenGuid = 38; // "{01234567-0123-0123-0123-012345678901}"
  11. __inline void MyStringFromGuid(PTSTR pstr, LPCGUID Guid)
  12. {
  13. wsprintf(pstr, TEXT("{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
  14. Guid->Data1,
  15. Guid->Data2,
  16. Guid->Data3,
  17. Guid->Data4[0], Guid->Data4[1],
  18. Guid->Data4[2], Guid->Data4[3], Guid->Data4[4], Guid->Data4[5], Guid->Data4[6], Guid->Data4[7]);
  19. }
  20. LONG KsGetFilterStatePropertySets(IN HANDLE hKsObject, OUT GUID *ppaPropertySets[], OUT int *pcPropertySets)
  21. {
  22. KSPROPERTY Property;
  23. ULONG cbData;
  24. LONG result;
  25. Property.Set = KSPROPSETID_Audio;
  26. Property.Id = KSPROPERTY_AUDIO_FILTER_STATE;
  27. Property.Flags = KSPROPERTY_TYPE_GET;
  28. if (DeviceIoControl(hKsObject, IOCTL_KS_PROPERTY,
  29. &Property, sizeof(Property),
  30. NULL, 0,
  31. &cbData, NULL))
  32. {
  33. // dprintf(TEXT("KsGetFilterStatePropertySets: succeeded, cbData=%d\n"), cbData);
  34. result = NO_ERROR;
  35. } else {
  36. result = GetLastError();
  37. // dprintf(TEXT("KsGetFilterStatePropertySets: failed getting FilterState property size, LastError=%d\n"), result);
  38. if (ERROR_MORE_DATA == result) {
  39. // dprintf(TEXT("KsGetFilterStatePropertySets: note: %d bytes in FilterState\n"), cbData);
  40. result = NO_ERROR;
  41. }
  42. }
  43. if (NO_ERROR == result) {
  44. if (cbData > 0) {
  45. LPGUID paPropertySets;
  46. paPropertySets = (LPGUID)HeapAlloc(hHeap, 0, cbData);
  47. if (paPropertySets) {
  48. Property.Set = KSPROPSETID_Audio;
  49. Property.Id = KSPROPERTY_AUDIO_FILTER_STATE;
  50. Property.Flags = KSPROPERTY_TYPE_GET;
  51. if (DeviceIoControl(hKsObject, IOCTL_KS_PROPERTY,
  52. &Property, sizeof(Property),
  53. paPropertySets, cbData,
  54. &cbData, NULL))
  55. {
  56. *ppaPropertySets = paPropertySets;
  57. *pcPropertySets = cbData / sizeof(paPropertySets[0]);
  58. } else {
  59. result = GetLastError();
  60. // dprintf(TEXT("KsGetFilterStatePropertySets: failed getting FilterState property, LastError=%d\n"), result);
  61. }
  62. if (NO_ERROR != result) {
  63. HeapFree(hHeap, 0, paPropertySets);
  64. }
  65. } else {
  66. result = ERROR_OUTOFMEMORY;
  67. }
  68. } else {
  69. *ppaPropertySets = NULL;
  70. *pcPropertySets = 0;
  71. }
  72. }
  73. return result;
  74. }
  75. LONG KsSerializePropertySetToReg(IN HANDLE hKsObject, IN LPCGUID PropertySet, IN HKEY hKey)
  76. {
  77. TCHAR strGuid[StrLenGuid+1];
  78. KSPROPERTY Property;
  79. ULONG cbData;
  80. LONG result;
  81. MyStringFromGuid(strGuid, PropertySet);
  82. // dprintf(TEXT("KsSerializePropertySetToReg: note: serializing set %s\n"), strGuid);
  83. Property.Set = *PropertySet;
  84. Property.Id = 0;
  85. Property.Flags = KSPROPERTY_TYPE_SERIALIZESET;
  86. if (DeviceIoControl(hKsObject, IOCTL_KS_PROPERTY,
  87. &Property, sizeof(Property),
  88. NULL, 0,
  89. &cbData, NULL))
  90. {
  91. // dprintf(TEXT("KsSerializePropertySetToReg: succeeded, cbData=%d\n"), cbData);
  92. result = NO_ERROR;
  93. } else {
  94. result = GetLastError();
  95. // dprintf(TEXT("KsSerializePropertySetToReg: failed getting serialized size, LastError=%d\n"), result);
  96. if (ERROR_MORE_DATA == result) {
  97. // dprintf(TEXT("KsSerializePropertySetToReg: note: %d bytes to serialize\n"), cbData);
  98. result = NO_ERROR;
  99. }
  100. }
  101. if (NO_ERROR == result && cbData > 0) {
  102. PVOID pvData = HeapAlloc(hHeap, 0, cbData);
  103. if (pvData) {
  104. Property.Set = *PropertySet;
  105. Property.Id = 0;
  106. Property.Flags = KSPROPERTY_TYPE_SERIALIZESET;
  107. if (DeviceIoControl(hKsObject, IOCTL_KS_PROPERTY,
  108. &Property, sizeof(Property),
  109. pvData, cbData,
  110. &cbData, NULL))
  111. {
  112. result = RegSetBinaryValue(hKey, strGuid, (PBYTE)pvData, cbData);
  113. } else {
  114. result = GetLastError();
  115. // dprintf(TEXT("KsSerializePropertySetToReg: failed to serialize, LastError=%d\n"), result);
  116. }
  117. HeapFree(hHeap, 0, pvData);
  118. } else {
  119. result = ERROR_OUTOFMEMORY;
  120. }
  121. }
  122. return result;
  123. }
  124. LONG KsSerializeFilterStateToReg(IN HANDLE hKsObject, IN HKEY hKey)
  125. {
  126. LPGUID paPropertySets;
  127. int cPropertySets;
  128. LONG result;
  129. result = KsGetFilterStatePropertySets(hKsObject, &paPropertySets, &cPropertySets);
  130. if (NO_ERROR == result && cPropertySets > 0) {
  131. int i;
  132. for (i = 0; i < cPropertySets; i++) {
  133. KsSerializePropertySetToReg(hKsObject, &paPropertySets[i], hKey);
  134. }
  135. HeapFree(hHeap, 0, paPropertySets);
  136. }
  137. return result;
  138. }
  139. LONG KsUnserializePropertySetFromReg(IN HANDLE hKsObject, IN LPCGUID PropertySet, IN HKEY hKey)
  140. {
  141. TCHAR strGuid[StrLenGuid+1];
  142. KSPROPERTY Property;
  143. PBYTE pData;
  144. ULONG cbData;
  145. LONG result;
  146. MyStringFromGuid(strGuid, PropertySet);
  147. // dprintf(TEXT("KsUnserializePropertySetFromReg: note: serializing set %s\n"), strGuid);
  148. result = RegQueryBinaryValue(hKey, strGuid, (PBYTE*)&pData, &cbData);
  149. if (NO_ERROR == result) {
  150. Property.Set = *PropertySet;
  151. Property.Id = 0;
  152. Property.Flags = KSPROPERTY_TYPE_UNSERIALIZESET;
  153. if (DeviceIoControl(hKsObject, IOCTL_KS_PROPERTY,
  154. &Property, sizeof(Property),
  155. pData, cbData,
  156. &cbData, NULL))
  157. {
  158. // dprintf(TEXT("KsUnserializePropertySetFromReg: succeeded\n"));
  159. result = NO_ERROR;
  160. } else {
  161. result = GetLastError();
  162. // dprintf(TEXT("KsUnserializePropertySetFromReg: failed to unserialize, LastError=%d\n"), result);
  163. }
  164. HeapFree(hHeap, 0, pData);
  165. }
  166. return result;
  167. }
  168. LONG KsUnserializeFilterStateFromReg(IN HANDLE hKsObject, IN HKEY hKey)
  169. {
  170. LPGUID paPropertySets;
  171. int cPropertySets;
  172. LONG result;
  173. result = KsGetFilterStatePropertySets(hKsObject, &paPropertySets, &cPropertySets);
  174. if (NO_ERROR == result && cPropertySets > 0) {
  175. int i;
  176. for (i = 0; i < cPropertySets; i++) {
  177. KsUnserializePropertySetFromReg(hKsObject, &paPropertySets[i], hKey);
  178. }
  179. HeapFree(hHeap, 0, paPropertySets);
  180. }
  181. return result;
  182. }
  183. LONG KsSetAudioGfxXxxTargetDeviceId(IN HANDLE hGfx, IN ULONG PropertyId, IN PCTSTR DeviceId)
  184. {
  185. KSPROPERTY Property;
  186. ULONG cbData;
  187. LONG result;
  188. ASSERT(hGfx);
  189. ASSERT(!IsBadStringPtr(DeviceId, (UINT_PTR)(-1)));
  190. ASSERT(lstrlen(DeviceId));
  191. Property.Set = KSPROPSETID_AudioGfx;
  192. Property.Id = PropertyId;
  193. Property.Flags = KSPROPERTY_TYPE_SET;
  194. cbData = (lstrlen(DeviceId) + 1) * sizeof(DeviceId[0]);
  195. if (DeviceIoControl(hGfx, IOCTL_KS_PROPERTY,
  196. &Property, sizeof(Property),
  197. (LPVOID)DeviceId, cbData,
  198. &cbData, NULL))
  199. {
  200. result = NO_ERROR;
  201. } else {
  202. result = GetLastError();
  203. dprintf(TEXT("KsSetAudioGfxXxxTargetDeviceId: failed, LastError=%d\n"), result);
  204. }
  205. return result;
  206. }
  207. LONG KsSetAudioGfxRenderTargetDeviceId(IN HANDLE hGfx, IN PCTSTR DeviceId)
  208. {
  209. return KsSetAudioGfxXxxTargetDeviceId(hGfx, KSPROPERTY_AUDIOGFX_RENDERTARGETDEVICEID, DeviceId);
  210. }
  211. LONG KsSetAudioGfxCaptureTargetDeviceId(IN HANDLE hGfx, IN PCTSTR DeviceId)
  212. {
  213. return KsSetAudioGfxXxxTargetDeviceId(hGfx, KSPROPERTY_AUDIOGFX_CAPTURETARGETDEVICEID, DeviceId);
  214. }