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.

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