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.

446 lines
14 KiB

  1. /* *************************************************************************
  2. ** INTEL Corporation Proprietary Information
  3. **
  4. ** This listing is supplied under the terms of a license
  5. ** agreement with INTEL Corporation and may not be copied
  6. ** nor disclosed except in accordance with the terms of
  7. ** that agreement.
  8. **
  9. ** Copyright (c) 1995 Intel Corporation.
  10. ** All Rights Reserved.
  11. **
  12. ** *************************************************************************
  13. */
  14. // $Author: KLILLEVO $
  15. // $Date: 31 Oct 1996 10:12:46 $
  16. // $Archive: S:\h26x\src\common\cdrvbase.cpv $
  17. // $Header: S:\h26x\src\common\cdrvbase.cpv 1.25 31 Oct 1996 10:12:46 KLILLEVO $
  18. // $Log: S:\h26x\src\common\cdrvbase.cpv $
  19. //
  20. // Rev 1.25 31 Oct 1996 10:12:46 KLILLEVO
  21. // changed from DBOUT to DBgLog
  22. //
  23. // Rev 1.24 04 Oct 1996 16:11:54 JMCVEIGH
  24. // In DrvOpen(), DecompPtr is now allocated if dwFlags indicate
  25. // ICMODE_DECOMPRESS *and* ICMODE_COMPRESS. After installing the ClearVideo
  26. // encoder, Adobe's Premiere would crash when compressing with the off-line.
  27. // Crash was due to accessing an unallocated version of DecompPtr.
  28. // Raj believes ClearVideo installed DCI. Possible penalty of this fix
  29. // is that we might allocate a decoder instance that is never used.
  30. //
  31. // Rev 1.23 26 Sep 1996 14:46:48 MBODART
  32. // Simplified version number definitions.
  33. // Bumped H.261 major version number to 4, reset build number to 001.
  34. //
  35. // Rev 1.22 12 Sep 1996 13:54:06 KLILLEVO
  36. // changed to Win32 memory allocation
  37. //
  38. // Rev 1.21 03 Sep 1996 16:17:58 PLUSARDI
  39. // updated for version 2.50 of 263 net
  40. //
  41. // Rev 1.20 23 Aug 1996 13:44:56 SCDAY
  42. // added version numbers for Quartz using #ifdef QUARTZ
  43. //
  44. // Rev 1.19 22 Aug 1996 10:17:14 PLUSARDI
  45. // updated for quartz version 3.05 for h261
  46. //
  47. // Rev 1.18 16 Aug 1996 11:31:28 CPERGIEX
  48. // updated not non-quartz build
  49. //
  50. // Rev 1.17 30 Jul 1996 12:57:22 PLUSARDI
  51. // updated for RTP version string
  52. //
  53. // Rev 1.16 11 Jul 1996 07:54:18 PLUSARDI
  54. // change the version number for h261 v3.05.003
  55. //
  56. // Rev 1.15 12 Jun 1996 09:47:22 KLILLEVO
  57. // updated version number
  58. //
  59. // Rev 1.14 28 Apr 1996 20:25:36 BECHOLS
  60. //
  61. // Merged the RTP code into the Main Base.
  62. //
  63. // Rev 1.13 21 Feb 1996 11:40:58 SCDAY
  64. // cleaned up compiler build warnings by putting ifdefs around definition of b
  65. //
  66. // Rev 1.12 02 Feb 1996 18:52:22 TRGARDOS
  67. // Added code to enable ICM_COMPRESS_FRAMES_INFO message.
  68. //
  69. // Rev 1.11 27 Dec 1995 14:11:36 RMCKENZX
  70. //
  71. // Added copyright notice
  72. //
  73. // Rev 1.10 13 Dec 1995 13:21:52 DBRUCKS
  74. // changed the h261 version string defintions to use V3.00
  75. //
  76. // Rev 1.9 01 Dec 1995 15:16:34 DBRUCKS
  77. // added VIDCF_QUALITY to support the quality slider.
  78. //
  79. // Rev 1.8 15 Nov 1995 15:58:56 AKASAI
  80. // Remove YVU9 from get info and return error "0" when unsupported.
  81. // (Integration point)
  82. //
  83. // Rev 1.7 09 Oct 1995 11:46:56 TRGARDOS
  84. //
  85. // Set VIDCF_CRUNCH flag to support bit rate control.
  86. //
  87. // Rev 1.6 20 Sep 1995 12:37:38 DBRUCKS
  88. // save the fcc in uppercase
  89. //
  90. // Rev 1.5 19 Sep 1995 15:41:00 TRGARDOS
  91. // Fixed four cc comparison code.
  92. //
  93. // Rev 1.4 19 Sep 1995 13:19:50 TRGARDOS
  94. // Changed drv_open to check ICOPEN flags.
  95. //
  96. // Rev 1.3 12 Sep 1995 15:45:38 DBRUCKS
  97. // add H261 ifdef to desc and name
  98. //
  99. // Rev 1.2 25 Aug 1995 11:53:00 TRGARDOS
  100. // Debugging key frame encoder.
  101. //
  102. // Rev 1.1 23 Aug 1995 12:27:16 DBRUCKS
  103. //
  104. // turn on color converter init
  105. //
  106. // Rev 1.0 31 Jul 1995 12:56:10 DBRUCKS
  107. // rename files
  108. //
  109. // Rev 1.1 21 Jul 1995 18:20:36 DBRUCKS
  110. // IsBadReadPtr fails with a NULL - protect against
  111. //
  112. // Rev 1.0 17 Jul 1995 14:43:58 CZHU
  113. // Initial revision.
  114. //
  115. // Rev 1.0 17 Jul 1995 14:14:28 CZHU
  116. // Initial revision.
  117. ;////////////////////////////////////////////////////////////////////////////
  118. #include "precomp.h"
  119. #ifdef H261
  120. #ifdef QUARTZ
  121. char szDescription[] = "Microsoft H.261 Video Codec";
  122. char szDesc_i420[] = "Intel 4:2:0 Video V3.05";
  123. char szName[] = "MS H.261";
  124. #else
  125. char szDescription[] = "Microsoft H.261 Video Codec";
  126. char szDesc_i420[] = "Intel 4:2:0 Video V3.00";
  127. char szName[] = "MS H.261";
  128. #endif
  129. #else // is H263
  130. #ifdef QUARTZ
  131. char szDescription[] = "Microsoft H.263 Video Codec";
  132. char szDesc_i420[] = "Intel 4:2:0 Video V2.55";
  133. char szName[] = "MS H.263";
  134. #else
  135. char szDescription[] = "Microsoft H.263 Video Codec";
  136. char szDesc_i420[] = "Intel 4:2:0 Video V2.50";
  137. char szName[] = "MS H.263";
  138. #endif
  139. #endif
  140. static U32 MakeFccUpperCase(U32 fcc);
  141. void MakeCode32(U16 selCode16)
  142. {
  143. BYTE desc[8];
  144. #define DSC_DEFAULT 0x40
  145. #define dsc_access 6
  146. GlobalReAlloc((HGLOBAL)selCode16, 0, GMEM_MODIFY|GMEM_MOVEABLE);
  147. _asm
  148. {
  149. mov bx, selCode16 ; bx = selector
  150. lea di, word ptr desc ; ES:DI --> desciptor
  151. mov ax,ss
  152. mov es,ax
  153. mov ax, 000Bh ; DPMI get descriptor
  154. int 31h
  155. ; set DEFAULT bit to make it a 32-bit code segment
  156. or desc.dsc_access,DSC_DEFAULT
  157. mov ax,000Ch ; DPMI set descriptor
  158. int 31h
  159. }
  160. }
  161. /******************************************************
  162. * DrvLoad()
  163. ******************************************************/
  164. BOOL PASCAL DrvLoad(void)
  165. {
  166. static int AlreadyInitialised = 0;
  167. if (!AlreadyInitialised) {
  168. AlreadyInitialised = 1;
  169. // H263InitDecoderGlobal();
  170. H263InitColorConvertorGlobal ();
  171. H263InitEncoderGlobal();
  172. }
  173. return TRUE;
  174. }
  175. ;////////////////////////////////////////////////////////////////////////////
  176. ;// Function: void PASCAL DrvFree(void);
  177. ;//
  178. ;// Description: Added header.
  179. ;//
  180. ;// History: 02/23/94 -BEN-
  181. ;////////////////////////////////////////////////////////////////////////////
  182. void PASCAL DrvFree(void)
  183. {
  184. return;
  185. }
  186. /**********************************************************
  187. * DrvOpen()
  188. * Arguments:
  189. * Pointer to ICOPEN data structure passed by
  190. * the system.
  191. * Returns:
  192. * If successful, returns a pointer to our INSTINFO data structure. That
  193. * will be passed back to us in the dwDriverID parameter on subsequent
  194. * system calls.
  195. * If unsuccessful, it returns NULL.
  196. **********************************************************/
  197. LPINST PASCAL DrvOpen(ICOPEN FAR * icinfo)
  198. {
  199. INSTINFO *lpInst;
  200. #ifdef _DEBUG
  201. char buf80[80];
  202. #endif
  203. // Allocate memory for our instance information structure, INSTINFO.
  204. if((lpInst = (INSTINFO *) HeapAlloc(GetProcessHeap(), 0, sizeof(INSTINFO))) == NULL){
  205. DBOUT("DrvOpen: Unable to ALLOC INSTINFO")
  206. return NULL;
  207. }
  208. /*
  209. * Store the four cc so we know which codec is open.
  210. * TODO: handle both lower case and upper case fourcc's.
  211. */
  212. lpInst->fccHandler = MakeFccUpperCase(icinfo->fccHandler);
  213. #ifdef _DEBUG
  214. wsprintf(buf80,"fccHandler=0x%lx",lpInst->fccHandler);
  215. DBOUT(buf80);
  216. #endif
  217. lpInst->CompPtr = NULL;
  218. lpInst->DecompPtr = NULL;
  219. // Check if being opened for decompression.
  220. if ( ((icinfo->dwFlags & ICMODE_DECOMPRESS) == ICMODE_DECOMPRESS) ||
  221. ((icinfo->dwFlags & ICMODE_FASTDECOMPRESS) == ICMODE_FASTDECOMPRESS) ){
  222. // Allocate memory for our decompressor specific instance data, DECINSTINFO.
  223. if((lpInst->DecompPtr = (DECINSTINFO *)
  224. HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DECINSTINFO))) == NULL){
  225. DBOUT("DrvOpen: Unable to ALLOC DECINSTINFO")
  226. HeapFree(GetProcessHeap(),0,lpInst);
  227. return NULL;
  228. }
  229. // Set flag indicating decoder instance is unitialized.
  230. lpInst->DecompPtr->Initialized = FALSE;
  231. }
  232. // Check if being opened for compression as H.263.
  233. if( (((icinfo->dwFlags & ICMODE_COMPRESS) == ICMODE_COMPRESS) ||
  234. ((icinfo->dwFlags & ICMODE_FASTCOMPRESS) == ICMODE_FASTCOMPRESS)) &&
  235. (lpInst->fccHandler == FOURCC_H263) )
  236. {
  237. // Allocate memory for our compressor specific instance data, COMPINSTINFO.
  238. if((lpInst->CompPtr = (COMPINSTINFO*)
  239. HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(COMPINSTINFO))) == NULL){
  240. DBOUT("DrvOpen: Unable to ALLOC COMPINSTINFO")
  241. if (lpInst->DecompPtr != NULL)
  242. HeapFree(GetProcessHeap(),0,lpInst->DecompPtr);
  243. HeapFree(GetProcessHeap(),0,lpInst);
  244. return NULL;
  245. }
  246. // Set flag indicating encoder instance is uninitialized.
  247. lpInst->CompPtr->Initialized = FALSE;
  248. lpInst->CompPtr->FrameRate = (float) 0;
  249. lpInst->CompPtr->DataRate = 0;
  250. #if 0
  251. // Allocate memory for our decompressor specific instance data, DECINSTINFO.
  252. // Previously we didn't force this - assumed application specified
  253. // decompressor needed to be allocated in dwFlags.
  254. // After installing ClearVideo encoder, Adobe Premiere crashed using off-line without this code.
  255. // Put same work around here (DECINSTINFO is fairly small)
  256. // Might be due to installation of DCI? JM
  257. if (lpInst->DecompPtr == NULL) {
  258. if((lpInst->DecompPtr = (DECINSTINFO *)
  259. HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DECINSTINFO))) == NULL){
  260. DBOUT("DrvOpen: Unable to ALLOC DECINSTINFO")
  261. HeapFree(GetProcessHeap(),0,lpInst);
  262. return NULL;
  263. }
  264. // Set flag indicating decoder instance is unitialized.
  265. lpInst->DecompPtr->Initialized = FALSE;
  266. }
  267. #endif
  268. }
  269. // Assign instance info flag with ICOPEN flag.
  270. lpInst->dwFlags = icinfo->dwFlags;
  271. // Disable codec by default. The client will send us a private message
  272. // to enable it.
  273. lpInst->enabled = FALSE;
  274. return lpInst;
  275. }
  276. DWORD PASCAL DrvClose(LPINST lpInst)
  277. {
  278. if(IsBadReadPtr((LPVOID)lpInst, sizeof(INSTINFO))){
  279. DBOUT("DrvClose: instance NULL")
  280. return 1;
  281. }
  282. if(lpInst->DecompPtr && // IsBadReadPtr errors on NT with NULL
  283. !IsBadReadPtr((LPVOID)lpInst->DecompPtr, sizeof(DECINSTINFO))){
  284. if(lpInst->DecompPtr->Initialized){
  285. H263TermDecoderInstance(lpInst->DecompPtr);
  286. }
  287. HeapFree(GetProcessHeap(),0,lpInst->DecompPtr);
  288. lpInst->DecompPtr = NULL;
  289. }
  290. if(lpInst->CompPtr && // IsBadReadPtr errors on NT with NULL
  291. !IsBadReadPtr((LPVOID)lpInst->CompPtr, sizeof(COMPINSTINFO))){
  292. if(lpInst->CompPtr->Initialized){
  293. H263TermEncoderInstance(lpInst->CompPtr);
  294. }
  295. HeapFree(GetProcessHeap(),0,lpInst->CompPtr);
  296. lpInst->CompPtr = NULL;
  297. }
  298. HeapFree(GetProcessHeap(),0,lpInst);
  299. return 1;
  300. }
  301. DWORD PASCAL DrvGetState(LPINST lpInst, LPVOID pv, DWORD dwSize)
  302. {
  303. // Return current state of compression options
  304. if (pv == NULL) return (sizeof(COMPINSTINFO));
  305. // check that incoming buffer is big enough
  306. if (dwSize < sizeof(COMPINSTINFO)) return 0;
  307. // Check instance pointer
  308. if (lpInst && lpInst->CompPtr)
  309. {
  310. // fill the incoming buffer
  311. _fmemcpy(pv, lpInst->CompPtr, (int)sizeof(COMPINSTINFO));
  312. return sizeof(COMPINSTINFO);
  313. }
  314. else
  315. return 0;
  316. }
  317. DWORD PASCAL DrvSetState(LPINST lpInst, LPVOID pv, DWORD dwSize)
  318. {
  319. // check that there is enough incoming data
  320. if (dwSize < sizeof(COMPINSTINFO)) return 0;
  321. // Check instance pointer
  322. if (lpInst && lpInst->CompPtr && pv)
  323. {
  324. // get data out of incoming buffer
  325. _fmemcpy(lpInst->CompPtr, pv, (int)sizeof(COMPINSTINFO));
  326. return sizeof(COMPINSTINFO);
  327. }
  328. else
  329. return 0;
  330. }
  331. DWORD PASCAL DrvGetInfo(LPINST lpInst, ICINFO FAR *icinfo, DWORD dwSize)
  332. {
  333. if (icinfo == NULL)
  334. return sizeof(ICINFO);
  335. if (dwSize < sizeof(ICINFO))
  336. return 0;
  337. if (!lpInst)
  338. return 0;
  339. icinfo->dwSize = sizeof(ICINFO);
  340. icinfo->fccType = ICTYPE_VIDEO;
  341. icinfo->fccHandler = lpInst->fccHandler;
  342. icinfo->dwVersion = 9002;
  343. MultiByteToWideChar(CP_ACP,0,szName,-1,icinfo->szName,16);
  344. if(lpInst->fccHandler == FOURCC_H263)
  345. {
  346. icinfo->dwFlags = VIDCF_TEMPORAL; // We support inter frame compression.
  347. icinfo->dwFlags |= VIDCF_FASTTEMPORALC; // We do not need ICM to provide previous frames on compress
  348. icinfo->dwFlags |= VIDCF_CRUNCH; // We support bit rate control
  349. icinfo->dwFlags |= VIDCF_QUALITY; // We support Quality
  350. MultiByteToWideChar(CP_ACP,0,szDescription,-1,icinfo->szDescription,128);
  351. }
  352. else if ((lpInst->fccHandler == FOURCC_YUV12) || (lpInst->fccHandler == FOURCC_IYUV))
  353. {
  354. icinfo->dwFlags = 0;
  355. MultiByteToWideChar(CP_ACP,0,szDesc_i420,-1,icinfo->szDescription,128);
  356. }
  357. else
  358. {
  359. DBOUT("Error: unsupported four cc.")
  360. return(0);
  361. }
  362. return sizeof(ICINFO);
  363. }
  364. /**************************************************************************
  365. *
  366. * MakeFccUpperCase().
  367. *
  368. * Convert the passed parameter to upper case. No change to chars not in
  369. * the set [a..z].
  370. *
  371. * returns input parameter in all upper case
  372. */
  373. static U32
  374. MakeFccUpperCase(
  375. U32 fcc)
  376. {
  377. U32 ret;
  378. unsigned char c;
  379. c = (unsigned char)(fcc & 0xFF); fcc >>= 8;
  380. ret = toupper(c);
  381. c = (unsigned char)(fcc & 0xFF); fcc >>= 8;
  382. ret += toupper(c) << 8;
  383. c = (unsigned char)(fcc & 0xFF); fcc >>= 8;
  384. ret += ((U32)toupper(c)) << 16;
  385. c = (unsigned char)(fcc & 0xFF);
  386. ret += ((U32)toupper(c)) << 24;
  387. return ret;
  388. } /* end MakeFccUpperCase() */