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.

460 lines
17 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. ;////////////////////////////////////////////////////////////////////////////
  15. ;//
  16. ;// $Author: SCDAY $
  17. ;// $Date: 31 Oct 1996 08:58:32 $
  18. ;// $Archive: S:\h26x\src\dec\d1dec.h_v $
  19. ;// $Header: S:\h26x\src\dec\d1dec.h_v 1.17 31 Oct 1996 08:58:32 SCDAY $
  20. ;// $Log: S:\h26x\src\dec\d1dec.h_v $
  21. ;//
  22. ;// Rev 1.17 31 Oct 1996 08:58:32 SCDAY
  23. ;// Raj added support for MMX decoder
  24. ;//
  25. ;// Rev 1.16 25 Sep 1996 17:34:02 BECHOLS
  26. ;// Added Snapshot fields to the Decoder Catalog.
  27. ;//
  28. ;// Rev 1.15 12 Sep 1996 14:22:50 MBODART
  29. ;// Replaced GlobalAlloc family with HeapAlloc in the H.261 decoder.
  30. ;//
  31. ;// Rev 1.14 06 Sep 1996 15:03:00 MBODART
  32. ;// Added performance counters ffor NT's perfmon.
  33. ;// New files: cxprf.cpp, cxprf.h, cxprfmac.h.
  34. ;// New directory: src\perf
  35. ;// Updated files: e1enc.{h,cpp}, d1dec.{h,cpp}, cdrvdefs.h, h261* makefiles.
  36. ;//
  37. ;// Rev 1.13 21 Aug 1996 18:59:36 RHAZRA
  38. ;// Added RTP fields to decoder catalog.
  39. ;//
  40. ;// Rev 1.12 05 Aug 1996 11:00:30 MBODART
  41. ;//
  42. ;// H.261 decoder rearchitecture:
  43. ;// Files changed: d1gob.cpp, d1mblk.{cpp,h}, d1dec.{cpp,h},
  44. ;// filelist.261, h261_32.mak
  45. ;// New files: d1bvriq.cpp, d1idct.cpp
  46. ;// Obsolete files: d1block.cpp
  47. ;// Work still to be done:
  48. ;// Update h261_mf.mak
  49. ;// Optimize uv pairing in d1bvriq.cpp and d1idct.cpp
  50. ;// Fix checksum code (it doesn't work now)
  51. ;// Put back in decoder stats
  52. ;//
  53. ;// Rev 1.11 29 Feb 1996 09:20:04 SCDAY
  54. ;// Added support for mirroring
  55. ;//
  56. ;// Rev 1.10 11 Jan 1996 16:53:26 DBRUCKS
  57. ;//
  58. ;// added flags to the DC structure (force on aspect ratio correction and
  59. ;// use block edge filter).
  60. ;//
  61. ;// Rev 1.9 09 Jan 1996 09:41:50 AKASAI
  62. ;// Updated copyright notice.
  63. ;//
  64. ;// Rev 1.8 26 Dec 1995 17:42:14 DBRUCKS
  65. ;// changed bTimerIsOn to bTimingThisFrame
  66. ;//
  67. ;// Rev 1.7 26 Dec 1995 12:49:00 DBRUCKS
  68. ;//
  69. ;// add timing variables to the catalog
  70. ;//
  71. ;// Rev 1.6 15 Nov 1995 14:28:46 AKASAI
  72. ;// Added support for YUV12 "if 0" old code with aspec correction and
  73. ;// 8 to 7 bit conversion. Added FrameCopy calls and DispFrame into structure.
  74. ;// (Integration point)
  75. ;//
  76. ;// Rev 1.5 01 Nov 1995 13:46:44 AKASAI
  77. ;// Added new element to T_H263DecoderCatalog, uFilterBBuffer, space for the
  78. ;// result of loop filter.
  79. ;//
  80. ;// Rev 1.4 26 Oct 1995 15:31:44 SCDAY
  81. ;//
  82. ;// Delta frames partially working -- changed main loops to accommodate
  83. ;// skipped macroblocks by detecting next startcode
  84. ;//
  85. ;// Rev 1.3 10 Oct 1995 14:57:42 SCDAY
  86. ;// added support for FCIF
  87. ;//
  88. ;// Rev 1.2 06 Oct 1995 15:31:22 SCDAY
  89. ;// Integrated with latest AKK d1block
  90. ;//
  91. ;// Rev 1.1 19 Sep 1995 15:25:00 SCDAY
  92. ;//
  93. ;// added H261 pict, GOB, MB/MBA parsing
  94. ;//
  95. ;// Rev 1.0 11 Sep 1995 13:51:08 SCDAY
  96. ;// Initial revision.
  97. ;//
  98. ;// Rev 1.13 01 Sep 1995 09:49:12 DBRUCKS
  99. ;// checkin partial ajdust pels changes
  100. ;//
  101. ;// Rev 1.12 29 Aug 1995 16:48:12 DBRUCKS
  102. ;// add YVU9_VPITCH
  103. ;//
  104. ;// Rev 1.11 28 Aug 1995 10:15:04 DBRUCKS
  105. ;// update to 5 July Spec and 8/25 Errata
  106. ;//
  107. ;// Rev 1.10 23 Aug 1995 12:25:10 DBRUCKS
  108. ;// Turn on the color converters
  109. ;//
  110. ;// Rev 1.9 14 Aug 1995 16:38:30 DBRUCKS
  111. ;// add hung type and clarify pCurBlock
  112. ;//
  113. ;// Rev 1.8 11 Aug 1995 17:30:00 DBRUCKS
  114. ;// copy source to bitstream
  115. ;//
  116. ;// Rev 1.7 11 Aug 1995 15:13:00 DBRUCKS
  117. ;// ready to integrate block level
  118. ;//
  119. ;// Rev 1.6 04 Aug 1995 15:56:32 TRGARDOS
  120. ;//
  121. ;// Put definition of PITCH into CDRVDEFS.H so that encoder
  122. ;// doesn't get a redefinition of MACRO warning.
  123. ;//
  124. ;// Rev 1.5 03 Aug 1995 10:37:54 TRGARDOS
  125. ;//
  126. ;// Moved picture header structure definition to cdrvsdef.h.
  127. ;//
  128. ;// Rev 1.4 02 Aug 1995 15:31:02 DBRUCKS
  129. ;// added GOB header fields and cleaned up comments
  130. ;//
  131. ;// Rev 1.3 01 Aug 1995 16:24:58 DBRUCKS
  132. ;// add the picture header fields
  133. ;//
  134. ;// Rev 1.2 31 Jul 1995 16:28:12 DBRUCKS
  135. ;// move loacl BITS defs to D3DEC.CPP
  136. ;//
  137. ;// Rev 1.1 31 Jul 1995 15:51:12 CZHU
  138. ;//
  139. ;// added quant field in the BlockActionStream structure.
  140. ;//
  141. ;// Rev 1.0 31 Jul 1995 13:00:06 DBRUCKS
  142. ;// Initial revision.
  143. ;//
  144. ;// Rev 1.2 28 Jul 1995 13:59:54 CZHU
  145. ;//
  146. ;// Added block action stream definition and defines for constants
  147. ;//
  148. ;// Rev 1.1 24 Jul 1995 14:59:30 CZHU
  149. ;//
  150. ;// Defined decoder catalog for H.263. Also defined block action stream
  151. ;//
  152. ;// Rev 1.0 17 Jul 1995 14:46:24 CZHU
  153. ;// Initial revision.
  154. ;//
  155. ;// Rev 1.0 17 Jul 1995 14:14:40 CZHU
  156. ;// Initial revision.
  157. ;////////////////////////////////////////////////////////////////////////////
  158. #ifndef __DECLOCS_H__
  159. #define __DECLOCS_H__
  160. /*
  161. This file declares structs which catalog the locations of various
  162. tables, structures, and arrays needed by the H263 decoder.
  163. */
  164. #define QCIF_WIDTH 176
  165. #define FCIF_WIDTH 352
  166. //#define PITCH 384
  167. #define YVU9_VPITCH 336
  168. #define U_OFFSET 192
  169. #define UMV_EXPAND_Y 16
  170. #define UMV_EXPAND_UV 8 // expanding for Unrestricted MV in each direction
  171. #define Y_START (UMV_EXPAND_Y * PITCH + UMV_EXPAND_Y)
  172. #define UV_START (UMV_EXPAND_UV * PITCH + UMV_EXPAND_UV)
  173. #define INSTANCE_DATA_FIXED_SIZE 512
  174. #define BLOCK_BUFFER_SIZE PITCH*8 ////// 8*8*4*6
  175. #define FILTER_BLOCK_BUFFER_SIZE 8*8 // 64 bytes for 8x8 block of U8
  176. #define BLOCK_BUFFER_OFFSET (6*8) // New
  177. typedef struct {
  178. U32 X32_YPlane; /* X32_-pointer to Y, V, and U planes */
  179. U32 X32_VPlane; /* Base plus offset is 32-bit aligned for */
  180. U32 X32_UPlane; /* all planes */
  181. } YUVFrame;
  182. #define SRC_FORMAT_QCIF 0
  183. #define SRC_FORMAT_CIF 1
  184. typedef struct {
  185. /* Here's the data about the frame shape and location */
  186. YUVFrame CurrFrame; /* Current frame */
  187. YUVFrame PrevFrame; /* Previous frame */
  188. YUVFrame PBFrame; /* frame to hold B blocks for H.263 */
  189. YUVFrame DispFrame; /* current frame being displayed */
  190. YUVFrame PostFrame; /* Buffer for post process and color convert */
  191. U8 * p16InstPostProcess; /* Segment containing PostFrm and ArchFrm */
  192. LPVOID a16InstPostProcess; /* Original alloc'd pointer for Post/ArchFrm.
  193. * p16InstPostProcess is a16InstPostProcess
  194. * rounded up to a 32-byte boundary.
  195. */
  196. U32 uFrameHeight; /* Actual dimensions of image. */
  197. U32 uFrameWidth;
  198. U32 uYActiveHeight; /* Dimensions of image for which blocks are */
  199. U32 uYActiveWidth; /* actually encoded. I.e. height and width */
  200. U32 uUVActiveHeight; /* padded to multiple of eight */
  201. U32 uUVActiveWidth;
  202. U32 uSz_VUPlanes; /* Space allocated for V and U planes */
  203. U32 uSz_YPlane; /* Space allocated for Y plane */
  204. U32 uSz_YVUPlanes; /* Space allocated for all planes */
  205. /************************************************************************/
  206. /* These three fields are needed for implementing Snapshot. */
  207. U32 SnapshotRequest; /* Flags defined below */
  208. HANDLE SnapshotEvent; /* Event for synchronization of Snapshot */
  209. LPVOID SnapshotBuffer; /* This is the buffer where Snapshot goes */
  210. /************************************************************************/
  211. /* The data pointed to below is NOT instance specific. On 16-bit Windows
  212. it is copied to the per-instance data segment. On 32-bit Windows, it
  213. is in the one and only data segment, and is just pointed to here. */
  214. U32 uMBBuffer; /* storage for a block */
  215. U32 uFilterBBuffer; /* storage for a block after loop filter */
  216. U32 X16_BlkDir; /* Ptr array of type T_BlkDir */
  217. U32 X16_BlkActionStream; /* Params for each block */
  218. X32 X32_BEFDescr; /* Catalogs eagerness & willingness to BEF */
  219. X32 X32_BEFDescrCopy; /* Address of copy of BEFDescr in BEF seg */
  220. X32 X32_BEFApplicationList; /* List of blocks to do Block Edge Filter */
  221. U32 X32_BitStream; /* Huffman encoded bitstream for one frame */
  222. U32 uSizeBitStreamBuffer; /* Number of bytes allocated for this frame */
  223. U32 uSrcFormat; /* Picture header information */
  224. U32 uPrevSrcFormat;
  225. U32 uTempRef;
  226. U32 uBFrameTempRef;
  227. U32 uPQuant;
  228. U32 uDBQuant;
  229. U16 bSplitScreen;
  230. U16 bCameraOn;
  231. U16 bFreezeRelease;
  232. U16 bKeyFrame;
  233. U16 bUnrestrictedMotionVectors;
  234. U16 bArithmeticCoding;
  235. U16 bAdvancedPrediction;
  236. U16 bPBFrame;
  237. U16 bCPM;
  238. U16 bReadSrcFormat;
  239. U16 bHiResStill;
  240. U16 bUnused;
  241. U32 uGroupNumber; /* GOB header information */
  242. U32 uGOBFrameID;
  243. U32 uGQuant;
  244. U16 bFoundGOBFrameID;
  245. U16 bCoded; /* MB header information */
  246. U32 uMBA;
  247. U32 uMBType;
  248. U32 uCBPC;
  249. U32 uCBPY;
  250. U32 uDQuant;
  251. U32 uMQuant;
  252. I8 i8MVDH;
  253. I8 i8MVDV;
  254. U32 uCBP;
  255. I16 i16LastMBA;
  256. U16 bPrevFrameLost; /* Flag affecting temporal filter */
  257. U32 Sz_BitStream; /* Space allocated for copy of BitStream */
  258. U32 Ticker; /* Frame counter */
  259. U16 ColorConvertor; /* Index of color convertor to use */
  260. int CCOutputPitch; /* Pitch for color converted output frame */
  261. U32 CCOffsetToLine0; /* Offest to first line of color conv frame */
  262. U16 DecoderType; /* Pick from H263, YUV9 */
  263. X16 X16_LumaAdjustment; /* Table to adjust brightness and contrast */
  264. X16 X16_ChromaAdjustment; /* Table to adjust saturation */
  265. /* The control code points to the flags with pointer to a BOOL */
  266. BOOL bAdjustLuma; /* Set if adjusting brightness and contrast */
  267. BOOL bAdjustChroma; /* Set if adjusting saturation */
  268. U16 BrightnessSetting; /* Value used to build adjustment tables */
  269. U16 ContrastSetting; /* Value used to build adjustment tables */
  270. U16 SaturationSetting; /* Value used to build adjustment tables */
  271. U16 SuppressChecksum; /* Flag indicates if should skip checksum */
  272. U16 iAPColorConvPrev;
  273. LPVOID pAPInstPrev; /* Handle PostFrm and ArchFrm for prev AP */
  274. // rearch
  275. X32 X32_InverseQuant; // NEW
  276. X32 X32_pN; // NEW
  277. X32 X32_uMBInfoStream; // PB-NEW
  278. // rearch
  279. /* Timing Statistics Variables */
  280. X32 X32_DecTimingInfo; /* Offset to */
  281. U32 uStatFrameCount; /* statistics frame counter */
  282. /* The following are needed in lower level routines */
  283. int bTimingThisFrame;
  284. U32 uStartLow;
  285. U32 uStartHigh;
  286. //#ifdef LOSS_RECOVERY
  287. I32 iVerifiedBsExt;
  288. I32 iValidBsExt;
  289. void *pBsTrailer;
  290. void *pBsInfo;
  291. U32 uNumOfPackets;
  292. //#endif
  293. /* Options */
  294. int bForceOnAspectRatioCorrection;
  295. int bUseBlockEdgeFilter;
  296. } T_H263DecoderCatalog;
  297. /////////////////////////////////////////////////////////////////////////////
  298. // Snapshot request flags, Ben - 09/25/96 //
  299. #define SNAPSHOT_REQUESTED 0xFFFFFFF0 //
  300. #define SNAPSHOT_COPY_STARTED 0xFFFFFFEF //
  301. #define SNAPSHOT_COPY_FINISHED 0xFFFFFFEE //
  302. #define SNAPSHOT_COPY_REJECTED 0xFFFFFFED //
  303. /////////////////////////////////////////////////////////////////////////////
  304. // rearch
  305. // ?? U32 or U8??
  306. typedef struct { // NEW
  307. U32 dInverseQuant; // NEW
  308. U32 dTotalRun; // NEW
  309. } T_IQ_INDEX; // NEW
  310. /* MBInfo
  311. *
  312. * A stream of T_MBInfo structs provides a place to hold information
  313. * about the macroblocks gathered during the first pass so it can
  314. * be used during the second pass for B-frame bi-directional motion
  315. * prediction. Each struct deals with one macroblock.
  316. */
  317. typedef struct { // PB-NEW
  318. I8 i8MBType; // AP-NEW added by Raj
  319. I8 i8MVDBx2;
  320. I8 i8MVDBy2;
  321. } T_MBInfo; // PB-NEW
  322. // rearch
  323. /* Block Type defines
  324. */
  325. #define BT_INTRA_DC 0 // Intra block without TCOEFF
  326. // assembly code assumes INTRA_DC is zero
  327. #define BT_INTRA 1 // Intra block
  328. #define BT_INTER 2 // Inter block
  329. #define BT_EMPTY 3 // Inter block without TCOEFF
  330. #define BT_ERROR 4
  331. /* T_BlkAction
  332. *
  333. * A stream of T_BlkAction structs provides information about the blocks to
  334. * be processed for a slice. Each struct deals with one block.
  335. */
  336. typedef struct {
  337. U8 u8BlkType; /* block type */
  338. I8 i8MVX; /* horizontal motion - mult by two for half pel */
  339. I8 i8MVY; /* vertical motion - mult by two for half pel */
  340. /* rename to u8Quant */
  341. U8 u8Quant; /* quantization level for this block */
  342. U32 pCurBlock; /* current image. */
  343. U32 pRefBlock; /* reference image. */
  344. U32 pBBlock; /* B block image */
  345. U32 uBlkNumber; /* for debugging */
  346. } T_BlkAction;
  347. typedef struct {
  348. X32 X32_BlkAddr; /* Addr of block in current frame buffer. */
  349. } T_BlkDir;
  350. #ifdef WIN32
  351. #else
  352. /* Return offsets for these structures. */
  353. U32 FAR H263DOffset_DequantizerTables ();
  354. /* Return size of fixed-size tables at start of instance data. */
  355. U32 FAR H263DSizeOf_FixedPart();
  356. #endif
  357. X32 FAR ASM_CALLTYPE DecodeVLC (
  358. U8 FAR *P16Instance, /* Base of instance data. */
  359. X16 X16_VLCStateTrans, /* Offset to State Transition tbl. */
  360. U16 FirstBitPosition, /* a.k.a. first state number. */
  361. X32 X32_SliceBase, /* Offset to Stream to decode. */
  362. X16 X16_CodeBookStream); /* Offset to place to put output. */
  363. #ifdef WIN32
  364. /*IN FAR ASM_CALLTYPE BlkCopy (
  365. void * SourceAddr,
  366. void * DestinationAddr,
  367. U32 TransferLength);
  368. */
  369. #else
  370. /*
  371. IN FAR ASM_CALLTYPE BlkCopy (
  372. X32 SourceAddr,
  373. unsigned int SourceSegNum,
  374. X32 DestinationAddr,
  375. unsigned int DestinationSegNum,
  376. U32 TransferLength);
  377. */
  378. #endif
  379. void FAR ASM_CALLTYPE MassageYVU9Format (
  380. U8 FAR * P16Instance, /* Base of instance data */
  381. U8 FAR * InputImage); /* Address of input YUV9 image */
  382. X32 FAR ASM_CALLTYPE DecodeSlice (
  383. U8 FAR * P16Instance, /* Base of instance data */
  384. U16 NumberOfMacroBlkRows, /* Number of rows in slice */
  385. U16 MacroBlkRowNum); /* First row in slice */
  386. void FAR ASM_CALLTYPE DequantizeAndInverseSlant (
  387. U8 FAR * P16Instance, /* Base of instance data */
  388. X32 BlkCodePtr, /* Offset to Block Codes */
  389. X16 X16_BlkActionStream, /* Offset to stream of descriptors */
  390. X16 X16_DQMatrices); /* Offset to the 63 DQ matrices */
  391. extern "C" {
  392. void FAR ASM_CALLTYPE FrameCopy (
  393. HPBYTE InputPlane, /* Address of input data. */
  394. HPBYTE OuptutPlane, /* Address of output data. */
  395. UN FrameHeight, /* Lines to copy. */
  396. UN FrameWidth, /* Columns to copy. */
  397. UN Pitch); /* Pitch. */
  398. void FAR ASM_CALLTYPE FrameMirror (
  399. HPBYTE InputPlane, /* Address of input data. */
  400. HPBYTE OuptutPlane, /* Address of output data. */
  401. UN FrameHeight, /* Lines to copy. */
  402. UN FrameWidth, /* Columns to copy. */
  403. UN Pitch); /* Pitch. */
  404. };
  405. #endif