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.

384 lines
11 KiB

  1. //==========================================================================;
  2. //
  3. // CDecoderVideoPort - Video Port interface implementation
  4. //
  5. // $Date: 14 Oct 1998 15:09:54 $
  6. // $Revision: 1.1 $
  7. // $Author: Tashjian $
  8. //
  9. // $Copyright: (c) 1997 - 1998 ATI Technologies Inc. All Rights Reserved. $
  10. //
  11. //==========================================================================;
  12. extern "C"
  13. {
  14. #include "strmini.h"
  15. #include "ksmedia.h"
  16. #include "ddkmapi.h"
  17. }
  18. #include "wdmdrv.h"
  19. #include "decvport.h"
  20. #include "capdebug.h"
  21. #include "vidstrm.h"
  22. /*^^*
  23. * CDecoderVideoPort()
  24. * Purpose : CDecoderVideoPort class constructor
  25. *
  26. * Inputs : PDEVICE_OBJECT pDeviceObject : pointer to the Driver object to access the Registry
  27. * CI2CScript * pCScript : pointer to CI2CScript class object
  28. *
  29. * Outputs : none
  30. * Author : IKLEBANOV
  31. *^^*/
  32. CDecoderVideoPort::CDecoderVideoPort(PDEVICE_OBJECT pDeviceObject)
  33. {
  34. // It's a right place to provide Video Port connection parameters
  35. // initialization. The custom parameters should be placed in the Registry
  36. // in a standard way.
  37. // The list of custom parameters includes:
  38. // - Clock type, the decoder runs off : single, double, QCLK
  39. // - VACTIVE / VRESET configuration
  40. // - HACTIVE / HRESET configuration
  41. // - 8 / 16 bits VideoPort connection
  42. // - connection type : SPI / embedded (in the case of 8 bits also called ByteSream)
  43. m_pDeviceObject = pDeviceObject;
  44. // zero is a valid ID, therefore, set to something
  45. // else to initialize it.
  46. m_ring3VideoPortHandle = -1;
  47. }
  48. void CDecoderVideoPort::Open()
  49. {
  50. }
  51. void CDecoderVideoPort::Close()
  52. {
  53. ReleaseRing0VideoPortHandle();
  54. m_ring3VideoPortHandle = -1;
  55. ReleaseRing0DirectDrawHandle();
  56. m_ring3DirectDrawHandle = 0;
  57. }
  58. BOOL CDecoderVideoPort::ReleaseRing0VideoPortHandle()
  59. {
  60. DWORD ddOut = DD_OK;
  61. DDCLOSEHANDLE ddClose;
  62. if (m_ring0VideoPortHandle != 0)
  63. {
  64. //DBGTRACE(("Stream %d releasing ring0 vport handle\n", streamNumber));
  65. ddClose.hHandle = m_ring0VideoPortHandle;
  66. DxApi(DD_DXAPI_CLOSEHANDLE, &ddClose, sizeof(ddClose), &ddOut, sizeof(ddOut));
  67. if (ddOut != DD_OK)
  68. {
  69. DBGERROR(("DD_DXAPI_CLOSEHANDLE failed.\n"));
  70. TRAP();
  71. return FALSE;
  72. }
  73. m_ring0VideoPortHandle = 0;
  74. }
  75. return TRUE;
  76. }
  77. BOOL CDecoderVideoPort::ReleaseRing0DirectDrawHandle()
  78. {
  79. DWORD ddOut = DD_OK;
  80. DDCLOSEHANDLE ddClose;
  81. if (m_ring0DirectDrawHandle != 0)
  82. {
  83. //DBGTRACE(("Bt829: Stream %d releasing ring0 ddraw handle\n", streamNumber));
  84. ddClose.hHandle = m_ring0DirectDrawHandle;
  85. DxApi(DD_DXAPI_CLOSEHANDLE, &ddClose, sizeof(ddClose), &ddOut, sizeof(ddOut));
  86. if (ddOut != DD_OK)
  87. {
  88. DBGERROR(("DD_DXAPI_CLOSEHANDLE failed.\n"));
  89. TRAP();
  90. return FALSE;
  91. }
  92. m_ring0DirectDrawHandle = 0;
  93. }
  94. return TRUE;
  95. }
  96. BOOL CDecoderVideoPort::RegisterForDirectDrawEvents(CWDMVideoPortStream* pStream)
  97. {
  98. DDREGISTERCALLBACK ddRegisterCallback;
  99. DWORD ddOut;
  100. // DBGTRACE(("Stream %d registering for DirectDraw events\n", streamNumber));
  101. // =============== DDEVENT_PRERESCHANGE ===============
  102. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  103. RtlZeroMemory(&ddOut, sizeof(ddOut));
  104. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  105. ddRegisterCallback.dwEvents = DDEVENT_PRERESCHANGE;
  106. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  107. ddRegisterCallback.pContext = pStream;
  108. DxApi(DD_DXAPI_REGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  109. if (ddOut != DD_OK)
  110. {
  111. DBGERROR(("DD_DXAPI_REGISTER_CALLBACK failed.\n"));
  112. TRAP();
  113. return FALSE;
  114. }
  115. // =============== DDEVENT_POSTRESCHANGE ==============
  116. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  117. RtlZeroMemory(&ddOut, sizeof(ddOut));
  118. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  119. ddRegisterCallback.dwEvents = DDEVENT_POSTRESCHANGE;
  120. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  121. ddRegisterCallback.pContext = pStream;
  122. DxApi(DD_DXAPI_REGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  123. if (ddOut != DD_OK)
  124. {
  125. DBGERROR(("DD_DXAPI_REGISTER_CALLBACK failed.\n"));
  126. TRAP();
  127. return FALSE;
  128. }
  129. // =============== DDEVENT_PREDOSBOX =================
  130. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  131. RtlZeroMemory(&ddOut, sizeof(ddOut));
  132. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  133. ddRegisterCallback.dwEvents = DDEVENT_PREDOSBOX;
  134. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  135. ddRegisterCallback.pContext = pStream;
  136. DxApi(DD_DXAPI_REGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  137. if (ddOut != DD_OK)
  138. {
  139. DBGERROR(("DD_DXAPI_REGISTER_CALLBACK failed.\n"));
  140. TRAP();
  141. return FALSE;
  142. }
  143. // =============== DDEVENT_POSTDOSBOX ================
  144. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  145. RtlZeroMemory(&ddOut, sizeof(ddOut));
  146. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  147. ddRegisterCallback.dwEvents = DDEVENT_POSTDOSBOX;
  148. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  149. ddRegisterCallback.pContext = pStream;
  150. DxApi(DD_DXAPI_REGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  151. if (ddOut != DD_OK)
  152. {
  153. DBGERROR(("DD_DXAPI_REGISTER_CALLBACK failed.\n"));
  154. TRAP();
  155. return FALSE;
  156. }
  157. return TRUE;
  158. }
  159. BOOL CDecoderVideoPort::UnregisterForDirectDrawEvents( CWDMVideoPortStream* pStream)
  160. {
  161. DDREGISTERCALLBACK ddRegisterCallback;
  162. DWORD ddOut;
  163. // DBGTRACE(("Stream %d UNregistering for DirectDraw events\n", m_pStreamObject->StreamNumber));
  164. // =============== DDEVENT_PRERESCHANGE ===============
  165. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  166. RtlZeroMemory(&ddOut, sizeof(ddOut));
  167. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  168. ddRegisterCallback.dwEvents = DDEVENT_PRERESCHANGE ;
  169. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  170. ddRegisterCallback.pContext = pStream;
  171. DxApi(DD_DXAPI_UNREGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  172. if (ddOut != DD_OK)
  173. {
  174. DBGERROR(("DD_DXAPI_UNREGISTER_CALLBACK failed.\n"));
  175. TRAP();
  176. return FALSE;
  177. }
  178. // =============== DDEVENT_POSTRESCHANGE ==============
  179. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  180. RtlZeroMemory(&ddOut, sizeof(ddOut));
  181. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  182. ddRegisterCallback.dwEvents = DDEVENT_POSTRESCHANGE;
  183. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  184. ddRegisterCallback.pContext = pStream;
  185. DxApi(DD_DXAPI_UNREGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  186. if (ddOut != DD_OK)
  187. {
  188. DBGERROR(("DD_DXAPI_UNREGISTER_CALLBACK failed.\n"));
  189. TRAP();
  190. return FALSE;
  191. }
  192. // =============== DDEVENT_PREDOSBOX ==================
  193. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  194. RtlZeroMemory(&ddOut, sizeof(ddOut));
  195. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  196. ddRegisterCallback.dwEvents = DDEVENT_PREDOSBOX;
  197. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  198. ddRegisterCallback.pContext = pStream;
  199. DxApi(DD_DXAPI_UNREGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  200. if (ddOut != DD_OK)
  201. {
  202. DBGERROR(("DD_DXAPI_UNREGISTER_CALLBACK failed.\n"));
  203. TRAP();
  204. return FALSE;
  205. }
  206. // =============== DDEVENT_POSTDOSBOX =================
  207. RtlZeroMemory(&ddRegisterCallback, sizeof(ddRegisterCallback));
  208. RtlZeroMemory(&ddOut, sizeof(ddOut));
  209. ddRegisterCallback.hDirectDraw = m_ring0DirectDrawHandle;
  210. ddRegisterCallback.dwEvents = DDEVENT_POSTDOSBOX;
  211. ddRegisterCallback.pfnCallback = DirectDrawEventCallback;
  212. ddRegisterCallback.pContext = pStream;
  213. DxApi(DD_DXAPI_UNREGISTER_CALLBACK, &ddRegisterCallback, sizeof(ddRegisterCallback), &ddOut, sizeof(ddOut));
  214. if (ddOut != DD_OK)
  215. {
  216. DBGERROR(("DD_DXAPI_UNREGISTER_CALLBACK failed.\n"));
  217. TRAP();
  218. return FALSE;
  219. }
  220. return TRUE;
  221. }
  222. BOOL CDecoderVideoPort::GetRing0DirectDrawHandle()
  223. {
  224. if (m_ring0DirectDrawHandle == 0)
  225. {
  226. // DBGTRACE(("Stream %d getting ring0 ddraw handle\n", streamNumber));
  227. DDOPENDIRECTDRAWIN ddOpenIn;
  228. DDOPENDIRECTDRAWOUT ddOpenOut;
  229. RtlZeroMemory(&ddOpenIn, sizeof(ddOpenIn));
  230. RtlZeroMemory(&ddOpenOut, sizeof(ddOpenOut));
  231. ddOpenIn.dwDirectDrawHandle = m_ring3DirectDrawHandle;
  232. ddOpenIn.pfnDirectDrawClose = DirectDrawEventCallback;
  233. ddOpenIn.pContext = this;
  234. DxApi(DD_DXAPI_OPENDIRECTDRAW, &ddOpenIn, sizeof(ddOpenIn), &ddOpenOut, sizeof(ddOpenOut));
  235. if (ddOpenOut.ddRVal != DD_OK)
  236. {
  237. m_ring0DirectDrawHandle = 0;
  238. DBGERROR(("DD_DXAPI_OPENDIRECTDRAW failed.\n"));
  239. TRAP();
  240. return FALSE;
  241. }
  242. else
  243. {
  244. m_ring0DirectDrawHandle = ddOpenOut.hDirectDraw;
  245. }
  246. }
  247. return TRUE;
  248. }
  249. BOOL CDecoderVideoPort::GetRing0VideoPortHandle()
  250. {
  251. if (m_ring0VideoPortHandle == 0)
  252. {
  253. // DBGTRACE(("Stream %d getting ring0 vport handle\n", streamNumber));
  254. DDOPENVIDEOPORTIN ddOpenVPIn;
  255. DDOPENVIDEOPORTOUT ddOpenVPOut;
  256. RtlZeroMemory(&ddOpenVPIn, sizeof(ddOpenVPIn));
  257. RtlZeroMemory(&ddOpenVPOut, sizeof(ddOpenVPOut));
  258. ddOpenVPIn.hDirectDraw = m_ring0DirectDrawHandle;
  259. ddOpenVPIn.pfnVideoPortClose = DirectDrawEventCallback;
  260. ddOpenVPIn.pContext = this;
  261. ddOpenVPIn.dwVideoPortHandle = m_ring3VideoPortHandle;
  262. DxApi(DD_DXAPI_OPENVIDEOPORT, &ddOpenVPIn, sizeof(ddOpenVPIn), &ddOpenVPOut, sizeof(ddOpenVPOut));
  263. if (ddOpenVPOut.ddRVal != DD_OK)
  264. {
  265. m_ring0VideoPortHandle = 0;
  266. DBGERROR(("DD_DXAPI_OPENVIDEOPORT failed.\n"));
  267. TRAP();
  268. return FALSE;
  269. }
  270. else
  271. {
  272. m_ring0VideoPortHandle = ddOpenVPOut.hVideoPort;
  273. }
  274. }
  275. return TRUE;
  276. }
  277. BOOL CDecoderVideoPort::ConfigVideoPortHandle(ULONG info)
  278. {
  279. if (m_ring3VideoPortHandle == -1)
  280. {
  281. m_ring3VideoPortHandle = info;
  282. if (!GetRing0VideoPortHandle())
  283. {
  284. return FALSE;
  285. }
  286. }
  287. return TRUE;
  288. }
  289. BOOL CDecoderVideoPort::ConfigDirectDrawHandle(ULONG_PTR info)
  290. {
  291. if (m_ring3DirectDrawHandle == NULL)
  292. {
  293. m_ring3DirectDrawHandle = info;
  294. if (!GetRing0DirectDrawHandle())
  295. {
  296. return FALSE;
  297. }
  298. }
  299. return TRUE;
  300. }