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.

830 lines
29 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: MDUDA $
  17. // $Date: 19 Mar 1997 14:58:04 $
  18. // $Archive: S:\h26x\src\enc\e3enc.h_v $
  19. // $Header: S:\h26x\src\enc\e3enc.h_v 1.87 19 Mar 1997 14:58:04 MDUDA $
  20. // $Log: S:\h26x\src\enc\e3enc.h_v $
  21. ;//
  22. ;// Rev 1.87 19 Mar 1997 14:58:04 MDUDA
  23. ;// Increased motion estimation stack space from 16k to 64k bytes.
  24. ;//
  25. ;// Rev 1.86 17 Mar 1997 20:19:50 MDUDA
  26. ;// Moved local storage to encoder catalog and allocated pseudo stack
  27. ;// space needed to work around problem with 16-bit apps that allocated
  28. ;// insufficient stack space.
  29. ;//
  30. ;// Rev 1.85 10 Feb 1997 11:43:28 JMCVEIGH
  31. ;//
  32. ;// Support for new interpretation of blocking filter -
  33. ;// allow for motion vectors outside of the reference picture.
  34. ;//
  35. ;// Rev 1.84 07 Feb 1997 10:58:14 CZHU
  36. ;// Added three entry in EC to remove static variable used in e3rtp.cpp
  37. ;//
  38. ;// Rev 1.83 05 Feb 1997 12:19:18 JMCVEIGH
  39. ;// Pass GOBHeaderPresent parameter to MMxEDTQ() for EMV bug fix
  40. ;// support latest H.263+ draft bitstream spec, and support for
  41. ;// separate improved PB-frame flag.
  42. ;//
  43. ;// Rev 1.82 30 Dec 1996 19:55:48 MDUDA
  44. ;// Added color convertor initializer prototype.
  45. ;//
  46. ;// Rev 1.81 19 Dec 1996 16:33:38 MDUDA
  47. ;// Modified call to colorCnvtFrame to support H263 backward compatibility.
  48. ;//
  49. ;// Rev 1.80 16 Dec 1996 17:49:48 JMCVEIGH
  50. ;// H263Plus flag.
  51. ;//
  52. ;// Rev 1.79 16 Dec 1996 13:35:30 MDUDA
  53. ;//
  54. ;// Added ColorConvertor field to Encoder Catalog.
  55. ;//
  56. ;// Rev 1.78 11 Dec 1996 15:03:58 JMCVEIGH
  57. ;//
  58. ;// Changed size of padding of encoder catalog to handle H.263+
  59. ;// options.
  60. ;//
  61. ;// Rev 1.77 10 Dec 1996 09:07:48 JMCVEIGH
  62. ;// Fixed bug in padding of T_H263EncoderCatalog to 512 bytes when
  63. ;// H263P not defined.
  64. ;//
  65. ;// Rev 1.76 09 Dec 1996 17:59:28 JMCVEIGH
  66. ;// Added support for arbitrary frame size support.
  67. ;// 4 <= width <= 352, 4 <= height <= 288, both multiples of 4.
  68. ;// Normally, application will pass identical (arbitrary) frame
  69. ;// sizes in lParam1 and lParam2 of CompressBegin(). If
  70. ;// cropping/stretching desired to convert to standard frame sizes,
  71. ;// application should pass the desired output size in lParam2 and
  72. ;// the input size in lParam1.
  73. ;//
  74. ;// Rev 1.75 09 Dec 1996 09:49:44 MDUDA
  75. ;// Modified for H263P.
  76. ;//
  77. ;// Rev 1.74 11 Nov 1996 09:12:28 JMCVEIGH
  78. ;// Added bPrevIntra. This is used to re-initialize the ME states
  79. ;// when the previous frame was intra coded and the current frame
  80. ;// is to be inter coded.
  81. ;//
  82. ;// Rev 1.73 06 Nov 1996 16:32:12 gmlim
  83. ;// Removed H263ModeC preprocessor definitions.
  84. ;//
  85. ;// Rev 1.72 05 Nov 1996 13:25:08 GMLIM
  86. ;// Added mode c support for mmx case.
  87. ;//
  88. ;// Rev 1.71 03 Nov 1996 19:01:26 gmlim
  89. ;// Parameters changed in PB_GOB_Q_RLE_VLC_WriteBS() for mode c.
  90. ;//
  91. ;// Rev 1.70 22 Oct 1996 14:51:52 KLILLEVO
  92. ;// Blocktype initialization in InitMEState() is now only called if
  93. ;// the AP mode has changed from the previous picture.
  94. ;//
  95. ;// Rev 1.69 10 Oct 1996 16:43:02 BNICKERS
  96. ;// Initial debugging of Extended Motion Vectors.
  97. ;//
  98. ;// Rev 1.68 04 Oct 1996 08:47:56 BNICKERS
  99. ;// Add EMV.
  100. ;//
  101. ;// Rev 1.67 12 Sep 1996 10:56:12 BNICKERS
  102. ;// Add arguments for thresholds and differentials.
  103. ;//
  104. ;// Rev 1.66 06 Sep 1996 16:12:28 KLILLEVO
  105. ;// fixed the logical problem that the inter code count was always
  106. ;// incremented no matter whether coefficients were transmitted or not
  107. ;//
  108. ;// Rev 1.65 22 Aug 1996 11:31:24 KLILLEVO
  109. ;// changed PB switch to work the same for IA as for MMX
  110. ;//
  111. ;// Rev 1.64 19 Aug 1996 13:49:04 BNICKERS
  112. ;// Provide threshold and differential variables for spatial filtering.
  113. ;//
  114. ;// Rev 1.63 25 Jun 1996 14:24:50 BNICKERS
  115. ;// Implement heuristic motion estimation for MMX, AP mode.
  116. ;//
  117. ;// Rev 1.62 30 May 1996 15:09:08 BNICKERS
  118. ;// Fixed minor error in recent IA ME speed improvements.
  119. ;//
  120. ;// Rev 1.61 29 May 1996 15:38:02 BNICKERS
  121. ;// Acceleration of IA version of ME.
  122. ;//
  123. ;// Rev 1.60 14 May 1996 12:18:44 BNICKERS
  124. ;// Initial debugging of MMx B-Frame ME.
  125. ;//
  126. ;// Rev 1.59 03 May 1996 14:59:32 KLILLEVO
  127. ;// added one parameter to MMXEDTQ() : pointer to B-frame stream of
  128. ;// run,lengt,sign triplets
  129. ;//
  130. ;// Rev 1.58 03 May 1996 10:55:00 KLILLEVO
  131. ;//
  132. ;// started integrating Brian's MMX PB-frames
  133. ;//
  134. ;// Rev 1.57 02 May 1996 12:01:02 BNICKERS
  135. ;// Initial integration of B Frame ME, MMX version.
  136. ;//
  137. ;// Rev 1.56 28 Apr 1996 19:56:52 BECHOLS
  138. ;// Enabled RTP header stuff in calls.
  139. ;//
  140. ;// Rev 1.55 26 Apr 1996 11:06:36 BECHOLS
  141. ;// Added rtp stuff... but still need to get rid of ifdef's
  142. ;//
  143. ;// Rev 1.54 26 Mar 1996 12:00:16 BNICKERS
  144. ;// Did some tuning for MMx encode.
  145. ;//
  146. ;// Rev 1.53 15 Mar 1996 15:57:32 BECHOLS
  147. ;//
  148. ;// Added support for monolithic MMx code.
  149. ;//
  150. ;// Rev 1.52 12 Mar 1996 13:26:52 KLILLEVO
  151. ;// new rate control with adaptive bit usage profile
  152. ;//
  153. ;// Rev 1.51 27 Feb 1996 14:12:56 KLILLEVO
  154. ;//
  155. ;// PB switch
  156. ;//
  157. ;// Rev 1.50 22 Feb 1996 18:48:50 BECHOLS
  158. ;//
  159. ;// Added declarations for MMX functions.
  160. ;//
  161. ;// Rev 1.49 24 Jan 1996 13:21:26 BNICKERS
  162. ;// Implement OBMC
  163. ;//
  164. ;// Rev 1.48 22 Jan 1996 17:13:22 BNICKERS
  165. ;// Add MBEdgeType to MacroBlock Action Descriptor.
  166. ;//
  167. ;// Rev 1.47 22 Jan 1996 16:29:20 TRGARDOS
  168. ;// Started adding bit counting structures and code.
  169. ;//
  170. ;// Rev 1.46 03 Jan 1996 12:19:02 TRGARDOS
  171. ;// Added bUseINISettings member to EC structure.
  172. ;//
  173. ;// Rev 1.45 02 Jan 1996 17:07:54 TRGARDOS
  174. ;// Moved colorCnvtFrame into excolcnv.cpp and made
  175. ;// color convertor functions static.
  176. ;//
  177. ;// Rev 1.44 27 Dec 1995 15:32:56 RMCKENZX
  178. ;// Added copyright notice
  179. ;//
  180. ;// Added uBitUsageProfile for BRC.
  181. ;// added a control to activate the chaned BRC
  182. ;// Hookup init from Registry instead of ini
  183. ;// Add a parameter to QRLE entry point - bRTPHeader flag
  184. ;// Add a variable to the encoder catalog to store the netx intra MB
  185. ;// Added comments
  186. ;// integrate with build 29
  187. //
  188. ////////////////////////////////////////////////////////////////////////////
  189. #ifndef __H263E_H__
  190. #define __H263E_H__
  191. /*
  192. * This file declares structs which catalog the locations of various
  193. * tables, structures, and arrays needed by the H263 encoder.
  194. */
  195. const U8 def263INTRA_QP = 16; // default QP values
  196. const U8 def263INTER_QP = 16;
  197. /*
  198. * Block description structure. Must be 16-byte aligned.
  199. * See e3mbad.inc for more detail on each structure entry.
  200. */
  201. typedef struct {
  202. U32 BlkOffset; // [0-3] Offset to 8*8 target block from start of Y plane.
  203. union {
  204. /*
  205. * Adress of reference block for P frame motion estimation.
  206. */
  207. U8 *PastRef; // [4-7] Address of 8*8 reference block.
  208. /*
  209. * MVf and MVb vectors for B-frame motion estimation as defined in
  210. * H.263 spec. The reference block addresses are generated for
  211. * frame differencing. The numbers are biased by 60H.
  212. */
  213. struct {
  214. U8 HMVf;
  215. U8 VMVf;
  216. U8 HMVb;
  217. U8 VMVb;
  218. } CandidateMV;
  219. } B4_7;
  220. struct { // Scratch variables used by ME.
  221. U8 HMVf;
  222. U8 VMVf;
  223. U8 HMVb;
  224. U8 VMVb;
  225. } BestMV;
  226. char PHMV; // [12] Horizontal motion vector for P block..
  227. char PVMV; // [13] Vertical motion vector for P block..
  228. char BHMV; // [14] Horizontal motion vector (delta?) for B block..
  229. char BVMV; // [15] Vertical motion vector (delta?) for B block..
  230. } T_Blk;
  231. const int sizeof_T_Blk = 16;
  232. /*
  233. * T_MBlockActionStream - Structure to keep side information for a MB
  234. * used by encoder. This structure must be 16-byte aligned when allocated.
  235. * CodedBlocks must be DWORD aligned. The entire structure must be a multiple
  236. * of 16 bytes, and must match the size of the structure in e3mbad.inc.
  237. */
  238. #define SIZEOF_PSEUDOSTACKSPACE (1024 * 64)
  239. typedef struct {
  240. U8 BlockType; // 0 -- See block types below.
  241. U8 MBEdgeType; // 1 -- 1 off if left edge | 2 right | 4 top | 8 bottom.
  242. U8 Unassigned1; // 2 --
  243. U8 FirstMEState; // 3 -- First State Num for Motion Estimation engine.
  244. U8 CodedBlocks; // 4 -- [6] End-of-Stream indicator
  245. // [0] indicates Y1 non-empty
  246. // [1...5] indicates Y2, Y3, Y4, U, V nonempty.
  247. // Other bits zero.
  248. U8 CodedBlocksB; // 5 -- [0...5] like CodedBlocks, but for B frame.
  249. // Set to 0 for non bi-di prediction.
  250. U8 Unassigned2[2]; // 6...7
  251. U32 SWD; // 8...11 Sum of weighted diffs, from motion estimation.
  252. U32 SWDB; // 12...15 Sum of weighted diffs, from B frame motion estimation.
  253. T_Blk BlkY1; // 16...31
  254. T_Blk BlkY2; // 32...47
  255. T_Blk BlkY3; // 48...63
  256. T_Blk BlkY4; // 64...79
  257. T_Blk BlkU; // 80...95
  258. T_Blk BlkV; // 96...111
  259. U8 COD; // 112 -- Coded macroblock indication. When set to "0"
  260. // indicates that macroblock is coded. If set to
  261. // "1", it indicates that the macroblock is not coded
  262. // and the rest of the macroblock layer is empty.
  263. U8 MBType; // 113 -- Macro block type, {INTER, INTER+Q, INTER4V, INTRA, INTRA+Q}
  264. U8 CBPC; // 114 -- Coded block pattern for chrominance.
  265. U8 MODB; // 115 -- Macroblock mode for B-blocks.
  266. U8 CBPB; // 116 -- Coded block pattern for B blocks.
  267. U8 CBPY; // 117 -- Coded block pattern for luminance.
  268. U8 DQUANT; // 118 -- Quantizer information. A two bit pattern to define
  269. // change in QUANT.
  270. U8 InterCodeCnt; // 119 -- Count number of times current MB has been intercoded.
  271. U8 Unassigned4[8];// 120...127 -- Pad out to a power of two.
  272. } T_MBlockActionStream;
  273. const int sizeof_T_MBlockActionStream = 128;
  274. /*
  275. * Block Types
  276. */
  277. const U8 INTERBLOCK = 0;
  278. const U8 INTRABLOCK = 1;
  279. const U8 INTERBIDI = 2;
  280. const U8 INTRABIDI = 3;
  281. const U8 INTER4MV = 4;
  282. const U8 IsINTRA = 1; // Mask to check for INTRA or ITNRABIDI.
  283. const U8 IsBIDI = 2; // Mask to check for INTRABIDI or INTERBIDI.
  284. /*
  285. * MB Types
  286. */
  287. const U8 INTER = 0;
  288. const U8 INTERQ = 1;
  289. const U8 INTER4V= 2;
  290. const U8 INTRA = 3;
  291. const U8 INTRAQ = 4;
  292. /*
  293. * MB Edge Types
  294. */
  295. const U8 MBEdgeTypeIsLeftEdge = 0xE;
  296. const U8 MBEdgeTypeIsRightEdge = 0xD;
  297. const U8 MBEdgeTypeIsTopEdge = 0xB;
  298. const U8 MBEdgeTypeIsBottomEdge = 0x7;
  299. /*
  300. * First ME state for ME engine
  301. */
  302. const U8 ForceIntra = 0;
  303. const U8 UpperLeft = 1;
  304. const U8 UpperEdge = 2;
  305. const U8 UpperRight = 3;
  306. const U8 LeftEdge = 4;
  307. const U8 CentralBlock = 5;
  308. const U8 RightEdge = 6;
  309. const U8 LowerLeft = 7;
  310. const U8 LowerEdge = 8;
  311. const U8 LowerRight = 9;
  312. const U8 NoVertLeftEdge = 10;
  313. const U8 NoVertCentralBlock = 11;
  314. const U8 NoVertRightEdge = 12;
  315. /*
  316. * Coded block bit masks.
  317. */
  318. const U8 Y1BLOCK = 0x01;
  319. const U8 Y2BLOCK = 0x02;
  320. const U8 Y3BLOCK = 0x04;
  321. const U8 Y4BLOCK = 0x08;
  322. const U8 UBLOCK = 0x10;
  323. const U8 VBLOCK = 0x20;
  324. const I32 GOBs_IN_CIF = 18;
  325. const I32 MBs_PER_GOB_CIF = 22;
  326. typedef struct {
  327. U8 StateNumInc_SelectCentralPt;
  328. U8 MVIncIdx_SelectCentralPt;
  329. U8 StateNumInc_SelectRef1;
  330. U8 MVIncIdx_SelectRef1;
  331. U8 StateNumInc_SelectRef2;
  332. U8 MVIncIdx_SelectRef2;
  333. U16 pad;
  334. } T_SADState;
  335. /*
  336. * Structure to store bit counts.
  337. */
  338. typedef struct {
  339. U32 PictureHeader; // 0 All of picture header.
  340. U32 GOBHeader; // 4 All of GOB Header.
  341. U32 MBHeader; // 8 All of MB header.
  342. U32 DQUANT; // 12 Bits spent on DQUANT.
  343. U32 MV; // 16 Bits spent on MV's.
  344. U32 Coefs; // 20 Total bits spent on coefs.
  345. U32 Coefs_Y; // 24 Total bits spent on Y coefs.
  346. U32 IntraDC_Y; // 28 Bits spent on IntraDC coefs for Y.
  347. U32 Coefs_C; // 32 Total bits spent on Chroma Coefs
  348. U32 IntraDC_C; // 36 Bits spent on IntraDC coefs for C.
  349. U32 CBPY; // 40 Bits spent on CBPY
  350. U32 MCBPC; // 44 Bits spent on MCBPC
  351. U32 Coded; // 48 Number of coded blocks.
  352. U32 num_intra; // 52 Number of intra coded blocks.
  353. U32 num_inter; // 56 Number of Inter coded blocks.
  354. U32 num_inter4v; // 60 Number of Inter4V coded blocks.
  355. } T_BitCounts;
  356. typedef struct {
  357. U32 MBStartBitOff; // Start of MB Data
  358. U8 CBPYBitOff; // from start of MB data
  359. U8 MVDBitOff;
  360. U8 BlkDataBitOff; // from start of MB data
  361. } T_FutrPMBData;
  362. #ifdef LOG_ENCODE_TIMINGS_ON // { LOG_ENCODE_TIMINGS_ON
  363. /* Encoder Timing Data - per frame
  364. */
  365. typedef struct {
  366. U32 uEncodeFrame;
  367. #ifdef DETAILED_ENCODE_TIMINGS_ON // { DETAILED_ENCODE_TIMINGS_ON
  368. U32 uInputCC;
  369. U32 uMotionEstimation;
  370. U32 uFDCT;
  371. U32 uQRLE;
  372. U32 uDecodeFrame;
  373. U32 uZeroingBuffer;
  374. #endif // } DETAILED_ENCODE_TIMINGS_ON
  375. } ENC_TIMING_INFO;
  376. #define ENC_TIMING_INFO_FRAME_COUNT 105
  377. #endif // } LOG_ENCODE_TIMINGS_ON
  378. /*
  379. * T_H263EncoderCatalog - Catalog of information needed for an instance.
  380. * This structure must be multiple of 16.
  381. */
  382. typedef struct {
  383. U8 *pU8_CurrFrm; // 0
  384. U8 *pU8_CurrFrm_YPlane; // 4 Pointers to current frame buffers.
  385. U8 *pU8_CurrFrm_VPlane; // 8
  386. U8 *pU8_CurrFrm_UPlane; // 12
  387. U8 *pU8_PrevFrm; // 16
  388. U8 *pU8_PrevFrm_YPlane; // 20 Pointers to previous frame buffers
  389. U8 *pU8_PrevFrm_VPlane; // 24
  390. U8 *pU8_PrevFrm_UPlane; // 28
  391. U8 *pU8_FutrFrm; // 32
  392. U8 *pU8_FutrFrm_YPlane; // 36 Pointers to previous frame buffers
  393. U8 *pU8_FutrFrm_VPlane; // 40
  394. U8 *pU8_FutrFrm_UPlane; // 44
  395. U8 *pU8_BidiFrm; // 48
  396. U8 *pU8_BFrm_YPlane; // 52 Pointers to B frame buffers.
  397. U8 *pU8_BFrm_UPlane; // 56
  398. U8 *pU8_BFrm_VPlane; // 60
  399. T_MBlockActionStream *pU8_MBlockActionStream; // 64 Pointer to macro block action stream.
  400. I32 *pU8_DCTCoefBuf; // 68 Pointer to GOB DCT coefficient buffer.
  401. U8 *pU8_BitStream; // 72 Pointer to bitstream buffer.
  402. U8 *pU8_BitStrCopy; // 76 Pointer to bitstream buffer
  403. // for the PB-frame
  404. T_H263FrameHeaderStruct PictureHeader;// 80..127 (48 bytes) // Picture layer header structure.
  405. UN FrameHeight; // 128
  406. UN FrameWidth; // 132
  407. FrameSize FrameSz; // 136 -- Define frame size: SQCIF, QCIF, CIF
  408. UN NumMBRows; // 140 -- Number of rows of MB's
  409. UN NumMBPerRow; // 144 -- Number of MB's in a row.
  410. UN NumMBs; // 148 -- Total number of MBs.
  411. U8 *pU8_RGB24Image; // 152
  412. U8 *pU8_MBlockCodeBookStream;// 156
  413. U8 *pU8_BlockCodeBookStream; // 160
  414. U8 *pU8_BlockOfInterCoeffs; // 164
  415. U8 *pU8_BlockOfIntraCoeffs; // 168
  416. U32 AvgIntraSAD; // 172 Average SAD for Intra macroblocks.
  417. LPDECINST pDecInstanceInfo; // 176 Private decoder instance info.
  418. BRCStateStruct BRCState; // 180 State variables for bitrate control (32 bytes)
  419. U8 u8EncodePBFrame; // 212 Should encoder encode PB frames
  420. U8 u8SavedBFrame; // 213 Do we have a B-Frame saved for
  421. // encoding PB-frame
  422. U8 bMakeNextFrameKey; // 214
  423. U8 bUseINISettings; // 215
  424. U32 GOBHeaderPresent; // 216...220 Flag which GOB headers are present.
  425. U32 LastSWDBeforeForcedP; // 220...224 The last SWD before B frames were turned off
  426. T_BitCounts Bits; // 224 .. 288
  427. U8 *pU8_PredictionScratchArea; // 288...292 Pointer to area for pre-computing predictions.
  428. U8 prevAP; // 292 AP mode for previous picture
  429. U8 prevUMV; // 293 UMV mode for previous picture (not used)
  430. U8 bPrevFrameIntra; // 294 Flag whether previous frame was intra coded (used to set the ME states)
  431. U8 Unassigned0[1]; // 295...295 available
  432. U32 uBitUsageProfile[19]; // 296...372 Table for storing bit usage profile
  433. // 19 is large enough for CIF
  434. // element 0...NumGOBs-1 stores cumulative bit usage
  435. // element NumGOBs stores the final frame size
  436. I8 *pI8_MBRVS_Luma; // 372..376 Pointer to area for Luma Run Value Sign Triplets.
  437. I8 *pI8_MBRVS_Chroma; // 376..380 Pointer to area for Chroma Run Value Sign Triplets.
  438. HANDLE hBsInfoStream; // 380..384 memory handle for blocks allocate for extended portion of bs
  439. void * pBsInfoStream; // 384..388 point to next BITSTREAM_INFO struct for next packet
  440. U32 uBase; // 388..392 byte offset of at the beginning of this packet from start
  441. // 392..396 of the whole bitstream;
  442. U32 uPacketSizeThreshold; // 396..400 the packet size used by the codec
  443. void * pBaseBsInfoStream; // 400..404 start of bitstream extension
  444. U32 uNumOfPackets; // 404..408
  445. U32 uNextIntraMB; // 408..412 Used to implement rolling intra MBs
  446. U32 uNumberForcedIntraMBs; // 412..416 Number of forced intras in each frame
  447. I8 *pI8_MBRVS_BLuma; // 416..420 Pointer to area for Luma Run Value Sign Triplets for the B-frame (MMX)
  448. I8 *pI8_MBRVS_BChroma; // 420..424 Pointer to area for Chroma Run Value Sign Triplets for the B-frame (MMX)
  449. U8 *pU8_Signature; // 424
  450. U8 *pU8_Signature_YPlane; // 428 Pointers to signature buffers
  451. #ifdef USE_BILINEAR_MSH26X
  452. U32 uActualFrameWidth; // 460+40 Actual (non-padded) frame width
  453. U32 uActualFrameHeight; // 464+40 Actual (non-padded) frame height
  454. U32 ColorConvertor; // 468+40 Input color convertor.
  455. #endif
  456. #ifdef H263P
  457. //NEWCHANGES
  458. U32 uBitOffset_currPacket; // 432+40 bit offset for current packet
  459. U8 *pBitStream_currPacket; // 436+40 pointer to current bitstream, last MB
  460. U8 *pBitStream_lastPacket; // 440+40 pointer to bitstream at last packet
  461. U8 *pPseudoStackSpace; // 444+40 pointer to buffer for motion estimation
  462. T_FutrPMBData *pFutrPMBData; // 448+40 pointer to buffer previously on local stack in
  463. I8 *pWeightForwMotion; // 452+40 values based on TRb and TRd
  464. I8 *pWeightBackMotion; // 456+40 values based on TRb and TRd
  465. U32 uActualFrameWidth; // 460+40 Actual (non-padded) frame width
  466. U32 uActualFrameHeight; // 464+40 Actual (non-padded) frame height
  467. U32 ColorConvertor; // 468+40 Input color convertor.
  468. U8 bH263Plus; // 469+40 Flag for using H.263+
  469. U8 prevDF; // 470+40 Deblocking filter mode for previous picture
  470. // sizeof_T_H263FrameHeaderStruct = 88
  471. U8 Unassigned2[2]; // Pad size to 512 bytes.
  472. #else
  473. #ifdef LOG_ENCODE_TIMINGS_ON // { LOG_ENCODE_TIMINGS_ON
  474. ENC_TIMING_INFO *pEncTimingInfo; // 432
  475. U32 uStatFrameCount; // 436
  476. int bTimingThisFrame; // 440
  477. U32 uStartLow; // 444
  478. U32 uStartHigh; // 448
  479. #ifdef USE_BILINEAR_MSH26X
  480. U8 Unassigned2[62]; // Pad size to 512 bytes.
  481. #else
  482. U8 Unassigned2[64]; // Pad size to 512 bytes.
  483. #endif
  484. #else // }{ LOG_ENCODE_TIMINGS_ON
  485. #ifdef USE_BILINEAR_MSH26X
  486. U8 Unassigned2[72]; // Pad size to 512 bytes.
  487. #else
  488. U8 Unassigned2[84]; // Pad size to 512 bytes.
  489. #endif
  490. #endif // } LOG_ENCODE_TIMINGS_ON
  491. #endif
  492. } T_H263EncoderCatalog;
  493. const int sizeof_T_H263EncoderCatalog = 512;
  494. /*
  495. * T_H263EncoderInstanceMemory
  496. * Memory layout for encoder instance. The memory is allocated
  497. * dynamically and the beginning of this structure is aligned to a
  498. * 32 byte boundary.
  499. * All arrays should be start on a DWORD boundary.
  500. * MBActionStream should start on a 16 byte boundary.
  501. */
  502. // Define bit stream buffer size.
  503. const unsigned int sizeof_bitstreambuf = 352*288*3/4;
  504. // This structure is allocated on a N-byte boundary, where N is the size of
  505. // a MacroBlock Action Descriptor, which must be a power of two.
  506. typedef struct {
  507. T_H263EncoderCatalog EC;
  508. U8 UnAssigned0[2560]; // so that MMX ME (EMV case) can read outside
  509. // of legal address range of MBActionStream.
  510. T_MBlockActionStream MBActionStream[22*18+3];
  511. U8 UnAssigned1[16];
  512. U8 u8CurrentPlane [ (288+16+8+144)*384 + 8 ];
  513. U8 u8Pad1[ 72 ];
  514. U8 u8PreviousPlane[ (16+288+16+8+144+8)*384 + 64]; // reconstructed past
  515. U8 u8FuturePlane [ (16+288+16+8+144+8)*384 + 0]; // reconstructed future
  516. U8 u8BPlane [ (288+16+8+144)*384 + 8 ]; // like current plane
  517. U8 u8Pad2[1928];
  518. U8 u8Signature[(16+288+16)*384 + 24];
  519. U8 u8Scratch1[4096];
  520. U8 u8BitStream [ sizeof_bitstreambuf ];
  521. U8 u8BitStrCopy[ sizeof_bitstreambuf ];
  522. /*
  523. * Allocate space for DCT coefficients for an entire GOB.
  524. * Each block of coefficients is stored in 32 DWORDS (2 coefs/DWORD)
  525. * and there can be up to 6 blocks in a macroblock (P frame),
  526. * and up to 22 macroblocks in a GOB (CIF size).
  527. */
  528. U32 UnAssigned2[6]; // insert 6 DWORDS to put DCT on 32 byte boundary.
  529. I32 piGOB_DCTCoefs[32*6*22]; // For best performance align to 32 byte boundary
  530. /*
  531. * Allocate scratch space for storage of prediction blocks. We need
  532. * enough space for a whole GOB, luma only. This is used for the
  533. * calculation of OBMC predictions only.
  534. */
  535. U8 u8PredictionScratchArea[16*384];
  536. // The following arrays are needed for MMX
  537. I8 i8MBRVS_Luma[65 * 3 * 22 * 4];
  538. I8 i8MBRVS_Chroma[65 * 3 * 22 * 2];
  539. DECINSTINFO DecInstanceInfo; // Private decoder instance.
  540. #if defined(H263P)
  541. U8 u8PseudoStackSpace[SIZEOF_PSEUDOSTACKSPACE];
  542. T_FutrPMBData FutrPMBData[GOBs_IN_CIF*MBs_PER_GOB_CIF + 1];
  543. I8 WeightForwMotion[128]; // values based on TRb and TRd
  544. I8 WeightBackMotion[128]; // values based on TRb and TRd
  545. #endif
  546. #ifdef LOG_ENCODE_TIMINGS_ON // { LOG_ENCODE_TIMINGS_ON
  547. ENC_TIMING_INFO EncTimingInfo[ENC_TIMING_INFO_FRAME_COUNT];
  548. #endif // { LOG_ENCODE_TIMINGS_ON
  549. } T_H263EncoderInstanceMemory;
  550. // Define offsets from Y to U planes, and U to V planes.
  551. const int YU_OFFSET = (288+16+8)*384;
  552. const int UV_OFFSET = 192;
  553. const int CurPrev_OFFSET = 181328; // Offset from current to previous frame buffer.
  554. /****************************************************************
  555. * Function prototypes
  556. ****************************************************************/
  557. #if defined(H263P) || defined(USE_BILINEAR_MSH26X)
  558. void colorCnvtFrame (
  559. U32 ColorConvertor,
  560. LPCODINST lpCompInst,
  561. ICCOMPRESS *lpicComp,
  562. U8 *YPlane,
  563. U8 *UPlane,
  564. U8 *VPlane
  565. );
  566. void colorCnvtInitialize(LPBITMAPINFOHEADER lpbiInput, int InputColorConvertor);
  567. #else
  568. void colorCnvtFrame(
  569. T_H263EncoderCatalog * EC,
  570. LPCODINST lpCompInst,
  571. ICCOMPRESS * lpicComp,
  572. U8 * YPlane,
  573. U8 * UPlane,
  574. U8 * VPlane
  575. );
  576. #endif
  577. void PutBits(
  578. unsigned int fieldval, // Value of field to write to stream.
  579. unsigned int fieldlen, // Length of field to be written
  580. unsigned char **pbs, // Pointer to current byte in bitstream
  581. unsigned char *bitoffset // bit offset in current byte of bitstream.
  582. );
  583. extern "C" void FORWARDDCT (T_MBlockActionStream * MBlockActionStream,
  584. U8 * TargetFrameBaseAddr,
  585. U8 * PreviousFrameBaseAddr,
  586. U8 * FutureFrameBaseAddr,
  587. I32 * CoeffStream,
  588. int IsBFrame,
  589. int IsAdvancedPrediction,
  590. int IsPOfPBPair,
  591. U8 * ScratchBlocks,
  592. int NumberOfMBlksInGOB
  593. );
  594. extern "C" void MOTIONESTIMATION (
  595. T_MBlockActionStream * MBlockActionStream,
  596. U8 * TargetFrameBaseAddr,
  597. U8 * PreviousFrameBaseAddr,
  598. U8 * FilteredFrameBaseAddr,
  599. int DoRadius15Search,
  600. int DoHalfPelEstimation,
  601. int DoBlockLevelVectors,
  602. #if defined(H263P)
  603. U8 * pPseudoStackSpace,
  604. #endif
  605. int DoSpatialFiltering,
  606. int ZeroVectorThreshold,
  607. int NonZeroMVDifferential,
  608. int BlockMVDifferential,
  609. int EmptyThreshold,
  610. int InterCodingThreshold,
  611. int IntraCodingDifferential,
  612. int SpatialFilteringThreshold,
  613. int SpatialFilteringDifferential,
  614. U32 * IntraSWDTotal,
  615. U32 * IntraSWDBlocks,
  616. U32 * InterSWDTotal,
  617. U32 * InterSWDBlocks
  618. );
  619. #ifdef USE_MMX // { USE_MMX
  620. extern "C" void MMxMESignaturePrep (U8 * PreviousFrameBaseAddr,
  621. U8 * SignatureBaseAddr,
  622. int FrameWidth,
  623. int FrameHeight
  624. );
  625. extern "C" void MMxEDTQ (
  626. T_MBlockActionStream * MBlockActionStream,
  627. U8 * TargetFrameBaseAddr,
  628. U8 * PreviousFrameBaseAddr,
  629. U8 * BTargetFrameBaseAddr,
  630. U8 * SignatureBaseAddr,
  631. I8 * WeightForWardMotion,
  632. I8 * WeightBackwardMotion,
  633. int FrameWidth,
  634. int DoHalfPelEstimation,
  635. int DoBlockLevelVectors,
  636. #if defined(H263P)
  637. U8 * pPseudoStackSpace,
  638. #endif
  639. int DoSpatialFiltering,
  640. int DoAdvancedPrediction,
  641. int DoBFrame,
  642. #if defined(H263P)
  643. int DoDeblockingFilter, // Only H.263+ should use this
  644. int DoImprovedPBFrames, // Only H.263+ should use this
  645. #endif
  646. int DoLumaBlocksInThisPass,
  647. int DoExtendedMotionVectors,
  648. #if defined(H263P)
  649. int GOBHeaderPresent,
  650. #endif
  651. int QuantizationLevel,
  652. int BQuantizationLevel,
  653. int BFrmZeroVectorThreshold,
  654. int SpatialFiltThreshold,
  655. int SpatialFiltDifferential,
  656. U32 * SWDTotal,
  657. U32 * BSWDTotal,
  658. I8 * CodeStreamCursor,
  659. I8 * CodeBStreamCursor
  660. );
  661. #endif // } USE_MMX
  662. extern "C" void BFRAMEMOTIONESTIMATION (
  663. T_MBlockActionStream * MBlockActionStream,
  664. U8 * TargetFrameBaseAddr,
  665. U8 * PreviousFrameBaseAddr,
  666. U8 * FutureFrameBaseAddr,
  667. I8 * WeightForWardMotion,
  668. I8 * WeightBackwardMotion,
  669. U32 ZeroVectorThreshold,
  670. #if defined(H263P)
  671. U8 * pPseudoStackSpace,
  672. #endif
  673. U32 NonZeroMVDifferential,
  674. U32 EmptyBlockThreshold,
  675. U32 * InterSWDTotal,
  676. U32 * InterSWDBlocks
  677. );
  678. extern "C" I8 * QUANTRLE(
  679. I32 *CoeffStr,
  680. I8 *CodeStr,
  681. I32 QP,
  682. I32 BlockType
  683. );
  684. extern "C" void MBEncodeVLC(
  685. I8 **,
  686. I8 **,
  687. U32 ,
  688. U8 **,
  689. U8 *,
  690. I32,
  691. I32
  692. );
  693. /*
  694. * Routine to quantize, rle, vlc and write to bitstream
  695. * for an entire GOB.
  696. */
  697. void GOB_Q_RLE_VLC_WriteBS(
  698. T_H263EncoderCatalog *EC,
  699. I32 *DCTCoefs,
  700. U8 **pBitStream,
  701. U8 *pBitOffset,
  702. T_FutrPMBData *FutrPMBData,
  703. U32 GOB,
  704. U32 QP,
  705. BOOL bRTPHeader,
  706. U32 StartingMB
  707. );
  708. void GOB_VLC_WriteBS(
  709. T_H263EncoderCatalog *EC,
  710. I8 *pMBRVS_Luma,
  711. I8 *pMBRVS_Chroma,
  712. U8 **pBitStream,
  713. U8 *pBitOffset,
  714. T_FutrPMBData *FutrPMBData, // Start of GOB
  715. U32 GOB,
  716. U32 QP,
  717. BOOL bRTPHeader,
  718. U32 StartingMB
  719. );
  720. void PB_GOB_Q_RLE_VLC_WriteBS(
  721. T_H263EncoderCatalog * EC,
  722. I32 * DCTCoefs,
  723. U8 * pP_BitStreamStart,
  724. U8 ** pPB_BitStream,
  725. U8 * pPB_BitOffset,
  726. const T_FutrPMBData * const FutrPMBData,
  727. const U32 GOB,
  728. const U32 QP,
  729. BOOL bRTPHeader
  730. );
  731. void PB_GOB_VLC_WriteBS(
  732. T_H263EncoderCatalog * EC,
  733. I8 * pMBRVS_Luma,
  734. I8 * pMBRVS_Chroma,
  735. U8 * pP_BitStreamStart,
  736. U8 ** pPB_BitStream,
  737. U8 * pPB_BitOffset,
  738. const T_FutrPMBData * const FutrPMBData,
  739. const U32 GOB,
  740. const U32 QP,
  741. BOOL bRTPHeader
  742. );
  743. void CopyBits(
  744. U8 **pDestBS,
  745. U8 *pDestBSOffset,
  746. const U8 *pSrcBS,
  747. const U32 uSrcBitOffset,
  748. const U32 uBits
  749. );
  750. void InitVLC(void);
  751. #ifdef DEBUG_ENC
  752. void trace(char *str);
  753. #endif
  754. #ifdef DEBUG_DCT
  755. void cnvt_fdct_output(unsigned short *DCTcoeff, int DCTarray[64], int BlockType);
  756. #endif
  757. struct T_MAXLEVEL_PTABLE {
  758. int maxlevel;
  759. int * ptable;
  760. };
  761. //extern "C" { UN FAR ASM_CALLTYPE H263EOffset_DecoderInstInfo(); }
  762. #endif // #ifndef _H263E_H_