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.

404 lines
12 KiB

  1. /*----------------------------------------------------------------------+
  2. | |
  3. | drvproc.c - driver procedure |
  4. | |
  5. | Copyright (c) 1990-1994 Microsoft Corporation. |
  6. | Portions Copyright Media Vision Inc. |
  7. | All Rights Reserved. |
  8. | |
  9. | You have a non-exclusive, worldwide, royalty-free, and perpetual |
  10. | license to use this source code in developing hardware, software |
  11. | (limited to drivers and other software required for hardware |
  12. | functionality), and firmware for video display and/or processing |
  13. | boards. Microsoft makes no warranties, express or implied, with |
  14. | respect to the Video 1 codec, including without limitation warranties |
  15. | of merchantability or fitness for a particular purpose. Microsoft |
  16. | shall not be liable for any damages whatsoever, including without |
  17. | limitation consequential damages arising from your use of the Video 1 |
  18. | codec. |
  19. | |
  20. +----------------------------------------------------------------------*/
  21. #include <windows.h>
  22. #include <win32.h>
  23. #include <mmsystem.h>
  24. #ifndef _INC_COMPDDK
  25. #define _INC_COMPDDK 50 /* version number */
  26. #endif
  27. #include <vfw.h>
  28. #include "msvidc.h"
  29. #ifdef _WIN32
  30. //#include <mmddk.h>
  31. //LONG FAR PASCAL DefDriverProc(DWORD dwDriverIdentifier, HANDLE driverID, UINT message, LONG lParam1, LONG lParam2);
  32. #endif
  33. HMODULE ghModule = NULL;
  34. /***************************************************************************
  35. * DriverProc - The entry point for an installable driver.
  36. *
  37. * PARAMETERS
  38. * dwDriverId: For most messages, <dwDriverId> is the DWORD
  39. * value that the driver returns in response to a <DRV_OPEN> message.
  40. * Each time that the driver is opened, through the <DrvOpen> API,
  41. * the driver receives a <DRV_OPEN> message and can return an
  42. * arbitrary, non-zero value. The installable driver interface
  43. * saves this value and returns a unique driver handle to the
  44. * application. Whenever the application sends a message to the
  45. * driver using the driver handle, the interface routes the message
  46. * to this entry point and passes the corresponding <dwDriverId>.
  47. * This mechanism allows the driver to use the same or different
  48. * identifiers for multiple opens but ensures that driver handles
  49. * are unique at the application interface layer.
  50. *
  51. * The following messages are not related to a particular open
  52. * instance of the driver. For these messages, the dwDriverId
  53. * will always be zero.
  54. *
  55. * DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  56. *
  57. * hDriver: This is the handle returned to the application by the
  58. * driver interface.
  59. *
  60. * uiMessage: The requested action to be performed. Message
  61. * values below <DRV_RESERVED> are used for globally defined messages.
  62. * Message values from <DRV_RESERVED> to <DRV_USER> are used for
  63. * defined driver protocols. Messages above <DRV_USER> are used
  64. * for driver specific messages.
  65. *
  66. * lParam1: Data for this message. Defined separately for
  67. * each message
  68. *
  69. * lParam2: Data for this message. Defined separately for
  70. * each message
  71. *
  72. * RETURNS
  73. * Defined separately for each message.
  74. *
  75. ***************************************************************************/
  76. #ifdef _WIN32
  77. // rely on whoever is loading us to synchronize load/free
  78. UINT LoadCount = 0;
  79. #endif
  80. LRESULT FAR PASCAL _LOADDS DriverProc(DWORD_PTR dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  81. {
  82. INSTINFO *pi = (INSTINFO *)dwDriverID;
  83. LPBITMAPINFOHEADER lpbiIn;
  84. LPBITMAPINFOHEADER lpbiOut;
  85. ICDECOMPRESSEX FAR *px;
  86. #ifdef _WIN32
  87. LRESULT lres;
  88. #endif
  89. switch (uiMessage)
  90. {
  91. case DRV_LOAD:
  92. #ifdef _WIN32
  93. if (ghModule) {
  94. // AVI explicitly loads us as well, but does not pass the
  95. // correct (as known by WINMM) driver handle.
  96. } else {
  97. ghModule = (HANDLE) GetDriverModuleHandle(hDriver);
  98. }
  99. lres = VideoLoad();
  100. if (lres) {
  101. ++LoadCount;
  102. }
  103. return lres;
  104. #else
  105. return (LRESULT) VideoLoad();
  106. #endif
  107. case DRV_FREE:
  108. VideoFree();
  109. #ifdef _WIN32
  110. if (--LoadCount) {
  111. } else {
  112. ghModule = NULL;
  113. }
  114. #endif
  115. return (LRESULT)1L;
  116. case DRV_OPEN:
  117. // if being opened with no open struct, then return a non-zero
  118. // value without actually opening
  119. if (lParam2 == 0L)
  120. return 0xFFFF0000;
  121. return (LRESULT)(DWORD_PTR)(UINT_PTR)VideoOpen((ICOPEN FAR *) lParam2);
  122. case DRV_CLOSE:
  123. #ifdef _WIN32
  124. if (dwDriverID != 0xFFFF0000)
  125. #else
  126. if (pi)
  127. #endif
  128. VideoClose(pi);
  129. return (LRESULT)1L;
  130. /*********************************************************************
  131. state messages
  132. *********************************************************************/
  133. case DRV_QUERYCONFIGURE: // configuration from drivers applet
  134. return (LRESULT)0L;
  135. case DRV_CONFIGURE:
  136. return DRV_OK;
  137. case ICM_CONFIGURE:
  138. //
  139. // return ICERR_OK if you will do a configure box, error otherwise
  140. //
  141. if (lParam1 == -1)
  142. return QueryConfigure(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  143. else
  144. return Configure(pi, (HWND)lParam1);
  145. case ICM_ABOUT:
  146. //
  147. // return ICERR_OK if you will do a about box, error otherwise
  148. //
  149. if (lParam1 == -1)
  150. return QueryAbout(pi) ? ICERR_OK : ICERR_UNSUPPORTED;
  151. else
  152. return About(pi, (HWND)lParam1);
  153. case ICM_GETSTATE:
  154. return GetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  155. case ICM_SETSTATE:
  156. return SetState(pi, (LPVOID)lParam1, (DWORD)lParam2);
  157. case ICM_GETINFO:
  158. return GetInfo(pi, (ICINFO FAR *)lParam1, (DWORD)lParam2);
  159. case ICM_GETDEFAULTQUALITY:
  160. if (lParam1)
  161. {
  162. *((LPDWORD)lParam1) = 7500;
  163. return ICERR_OK;
  164. }
  165. break;
  166. /*********************************************************************
  167. get/set messages
  168. *********************************************************************/
  169. case ICM_GET:
  170. break;
  171. /*********************************************************************
  172. compression messages
  173. *********************************************************************/
  174. case ICM_COMPRESS_QUERY:
  175. return CompressQuery(pi,
  176. (LPBITMAPINFOHEADER)lParam1,
  177. (LPBITMAPINFOHEADER)lParam2);
  178. case ICM_COMPRESS_BEGIN:
  179. return CompressBegin(pi,
  180. (LPBITMAPINFOHEADER)lParam1,
  181. (LPBITMAPINFOHEADER)lParam2);
  182. case ICM_COMPRESS_GET_FORMAT:
  183. return CompressGetFormat(pi,
  184. (LPBITMAPINFOHEADER)lParam1,
  185. (LPBITMAPINFOHEADER)lParam2);
  186. case ICM_COMPRESS_GET_SIZE:
  187. return CompressGetSize(pi,
  188. (LPBITMAPINFOHEADER)lParam1,
  189. (LPBITMAPINFOHEADER)lParam2);
  190. case ICM_COMPRESS:
  191. return Compress(pi,
  192. (ICCOMPRESS FAR *)lParam1, (DWORD)lParam2);
  193. case ICM_COMPRESS_END:
  194. return CompressEnd(pi);
  195. case ICM_SET_STATUS_PROC:
  196. // DPF(("ICM_SET_STATUS_PROC\n"));
  197. pi->Status = ((ICSETSTATUSPROC FAR *) lParam1)->Status;
  198. pi->lParam = ((ICSETSTATUSPROC FAR *) lParam1)->lParam;
  199. return 0;
  200. /*********************************************************************
  201. decompress format query messages
  202. *********************************************************************/
  203. case ICM_DECOMPRESS_GET_FORMAT:
  204. return DecompressGetFormat(pi,
  205. (LPBITMAPINFOHEADER)lParam1,
  206. (LPBITMAPINFOHEADER)lParam2);
  207. case ICM_DECOMPRESS_GET_PALETTE:
  208. return DecompressGetPalette(pi,
  209. (LPBITMAPINFOHEADER)lParam1,
  210. (LPBITMAPINFOHEADER)lParam2);
  211. /*********************************************************************
  212. decompress (old) messages, map these to the new (ex) messages
  213. *********************************************************************/
  214. case ICM_DECOMPRESS_QUERY:
  215. lpbiIn = (LPBITMAPINFOHEADER)lParam1;
  216. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  217. return DecompressQuery(pi,0,
  218. lpbiIn,NULL,
  219. 0,0,-1,-1,
  220. lpbiOut,NULL,
  221. 0,0,-1,-1);
  222. case ICM_DECOMPRESS_BEGIN:
  223. lpbiIn = (LPBITMAPINFOHEADER)lParam1;
  224. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  225. return DecompressBegin(pi,0,
  226. lpbiIn,NULL,
  227. 0,0,-1,-1,
  228. lpbiOut,NULL,
  229. 0,0,-1,-1);
  230. case ICM_DECOMPRESS:
  231. px = (ICDECOMPRESSEX FAR *)lParam1;
  232. return Decompress(pi,0,
  233. px->lpbiSrc,px->lpSrc,
  234. 0, 0, -1, -1,
  235. px->lpbiDst,px->lpDst,
  236. 0, 0, -1, -1);
  237. case ICM_DECOMPRESS_END:
  238. return DecompressEnd(pi);
  239. /*********************************************************************
  240. decompress (ex) messages
  241. *********************************************************************/
  242. case ICM_DECOMPRESSEX_QUERY:
  243. px = (ICDECOMPRESSEX FAR *)lParam1;
  244. return DecompressQuery(pi,
  245. px->dwFlags,
  246. px->lpbiSrc,px->lpSrc,
  247. px->xSrc,px->ySrc,px->dxSrc,px->dySrc,
  248. px->lpbiDst,px->lpDst,
  249. px->xDst,px->yDst,px->dxDst,px->dyDst);
  250. case ICM_DECOMPRESSEX_BEGIN:
  251. px = (ICDECOMPRESSEX FAR *)lParam1;
  252. return DecompressBegin(pi,
  253. px->dwFlags,
  254. px->lpbiSrc,px->lpSrc,
  255. px->xSrc,px->ySrc,px->dxSrc,px->dySrc,
  256. px->lpbiDst,px->lpDst,
  257. px->xDst,px->yDst,px->dxDst,px->dyDst);
  258. case ICM_DECOMPRESSEX:
  259. px = (ICDECOMPRESSEX FAR *)lParam1;
  260. return Decompress(pi,
  261. px->dwFlags,
  262. px->lpbiSrc,px->lpSrc,
  263. px->xSrc,px->ySrc,px->dxSrc,px->dySrc,
  264. px->lpbiDst,px->lpDst,
  265. px->xDst,px->yDst,px->dxDst,px->dyDst);
  266. case ICM_DECOMPRESSEX_END:
  267. return DecompressEnd(pi);
  268. /*********************************************************************
  269. draw messages
  270. *********************************************************************/
  271. case ICM_DRAW_BEGIN:
  272. return DrawBegin(pi,(ICDRAWBEGIN FAR *)lParam1, (DWORD)lParam2);
  273. case ICM_DRAW:
  274. return Draw(pi,(ICDRAW FAR *)lParam1, (DWORD)lParam2);
  275. case ICM_DRAW_END:
  276. return DrawEnd(pi);
  277. /*********************************************************************
  278. standard driver messages
  279. *********************************************************************/
  280. case DRV_DISABLE:
  281. return (LRESULT)1L;
  282. case DRV_ENABLE:
  283. return (LRESULT)1L;
  284. case DRV_INSTALL:
  285. return (LRESULT)DRV_OK;
  286. case DRV_REMOVE:
  287. return (LRESULT)DRV_OK;
  288. }
  289. if (uiMessage < DRV_USER)
  290. return DefDriverProc(dwDriverID, hDriver, uiMessage,lParam1,lParam2);
  291. else
  292. return ICERR_UNSUPPORTED;
  293. }
  294. #ifdef _WIN32
  295. #if 0
  296. BOOL DllInstanceInit(PVOID hModule, ULONG Reason, PCONTEXT pContext)
  297. {
  298. if (Reason == DLL_PROCESS_ATTACH) {
  299. ghModule = (HANDLE) hModule;
  300. }
  301. return TRUE;
  302. }
  303. #endif
  304. #else
  305. /****************************************************************************
  306. * LibMain - Library initialization code.
  307. *
  308. * PARAMETERS
  309. * hModule: Our module handle.
  310. *
  311. * wHeapSize: The heap size from the .def file.
  312. *
  313. * lpCmdLine: The command line.
  314. *
  315. * Returns 1 if the initialization was successful and 0 otherwise.
  316. ***************************************************************************/
  317. int NEAR PASCAL LibMain(HMODULE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  318. {
  319. ghModule = hModule;
  320. return 1;
  321. }
  322. #endif